1

How can I change the equation font from Cambria Math to any other font of only numbers in all slides of Powerpoint using VBA?

I have used the below code to do the same. However, I am not getting the desired results.

Sub ChangeFontMathSymbols()
    Dim regX As Object
    Dim osld As Slide
    Dim oshp As Shape
    Dim strInput As String
    Dim b_found As Boolean
    Dim iRow As Integer
    Dim iCol As Integer

    Set regX = CreateObject("vbscript.regexp")
    With regX
        .Global = True
        .Pattern = "\d"
    End With
    For Each osld In ActivePresentation.Slides
        For Each oshp In osld.Shapes
            If oshp.HasTable Then
                For iRow = 1 To oshp.Table.Rows.Count
                    For iCol = 1 To oshp.Table.Columns.Count
                        strInput = oshp.Table.Cell(iRow, iCol).Shape.TextFrame.TextRange.Text
                        b_found = regX.Test(strInput)
                        If b_found = True Then

                             Set myMatches = regX.Execute(strInput)
                             For Each myMatch In myMatches
                            oshp.Table.Cell(iRow, iCol).Shape.TextFrame.TextRange.Characters(myMatch.FirstIndex + 1, myMatch.Length).Characters.Font.Name = "Helvetica"
                            Next
                        End If
                    Next iCol
                Next iRow
            Else
                If oshp.HasTextFrame Then
                    If oshp.TextFrame.HasText Then
                        strInput = oshp.TextFrame.TextRange.Text
                        b_found = regX.Test(strInput)
                        If b_found = True Then

                            Set myMatches = regX.Execute(strInput)
                                For Each myMatch In myMatches
                                    oshp.TextFrame.TextRange.Characters(myMatch.FirstIndex + 1, myMatch.Length).Characters.Font.Name = "Helvetica"
                                Next

                        End If
                    End If
                End If
            End If
        Next oshp
    Next osld
    Set regX = Nothing
End Sub
N Vinay
  • 11
  • 2
  • The last answer to this question says Cambria is the only supported font https://superuser.com/questions/1203374/change-default-math-font-in-powerpoint – Oran G. Utan Feb 10 '23 at 13:43
  • @Bradipo - Thank you for sharing this with me. Is there any way of changing the numbers in the equation to ab normal text using VBA? – N Vinay Feb 13 '23 at 11:12
  • I will try and look, it's an interesting question. However I am still learning so I cannot promise I will get to something. – Oran G. Utan Feb 13 '23 at 13:26
  • I tried to manually change the font of a number in an equation and nothing happened, I would say the font editing cannot be accessed at all for Math. Maybe (but with capital "M") it could be done by working on the XML @John Korchok, do you think it would be possible? – Oran G. Utan Feb 16 '23 at 09:50
  • @Bradipo - You can manually change the font of a number in an equation by first changing it to 'ab normal' text and then you can select the desired font. – N Vinay Feb 16 '23 at 15:05
  • After trying for a couple of hours today, I would say it is not possible: the conversion to normal text method seems to be available only for Word (https://learn.microsoft.com/en-us/office/vba/api/word.omath.converttonormaltext) and all my attempts have failed. – Oran G. Utan Mar 18 '23 at 18:03

0 Answers0