首页 > 解决方案 > 用于更改 Powerpoint 演示文稿中所有方程式颜色的宏

问题描述

我正在制作一个包含大量数学方程式的 PowerPoint 演示文稿。我想问一下是否有任何方法可以自动更改这些方程式的颜色。我找到了一个解决方案,但它适用于那里的 Word 文档: https ://www.codeproject.com/Tips/1378034/Macro-to-Change-the-Color-of-all-Equations-in-a-Wo

Sub Change_Equation_Color()
  'Macro to Change the Font Color of all Equations in a Word Document
   Dim Eq As OMath
   For Each Eq In ActiveDocument.OMaths
   Eq.Range.Select
   Selection.Font.ColorIndex = wdDarkBlue 'Choose Color here, e.g. wdBlack
   'Selection.Font.TextColor.RGB = RGB(255, 0, 255) 'To use RGB color, uncomment this line and comment the one above
Next
End Sub

不幸的是,这个宏在 PowerPoint 中不起作用。您能否为此提供任何解决方案?

谢谢!

标签: vbapowerpointequation

解决方案


这是 PowerPoint 等价物:

Sub ColorEquation()
    Dim oSlide As Slide
    Dim oShape As Shape
    For Each oSlide In ActivePresentation.Slides
        For Each oShape In oSlide.Shapes
            If oShape.HasTextFrame Then
                If oShape.TextFrame2.HasText Then
                    If oShape.TextFrame2.TextRange.MathZones.Length > 0 Then
                        oShape.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 255)
                    End If
                End If
            End If
        Next oShape
    Next oSlide
End Sub

推荐阅读