问题描述
我正在用许多数学方程式进行PowerPoint演示。 我想问一下是否有任何方法可以自动更改这些方程式的颜色。 我找到了一个解决方案,但是它是针对Word文档的: @L_404_0@
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,255) 'To use RGB color,uncomment this line and comment the one above
Next
End Sub
不幸的是,此宏在PowerPoint中不起作用。您能为此提供任何解决方案吗?
谢谢!
解决方法
相当于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,255)
End If
End If
End If
Next oShape
Next oSlide
End Sub
,
在第 8 行使用 Count 而不是 Length。
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.Count > 0 Then
oShape.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255,255)
End If
End If
End If
Next oShape
Next oSlide
End Sub