如何使用 VBA 使整个 PowerPoint 演示文稿中的字体保持一致?
我是 VBA 新手,所以我使用的代码可能完全错误,但这里是:
Sub FontChange()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
shp.TextFrame.TextRange.Font
.Size = 12
.Name = "Bauhaus 93"
.Bold = False
.Color.RGB = RGB(255, 127, 255)
Next shp
Next sld
End Sub
提前感谢您的帮助。
如果您想要更改不在占位符中的文本,请对韦恩版本进行一些修改。并进行一些测试,以确保所讨论的形状 a) 可以包含文本(线条等形状不能),如果是的话 b) 它有一些文本需要修改。
Option Explicit
Sub FontChange()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then ' Not all shapes do
If shp.TextFrame.HasText Then ' the shape may contain no text
With shp.TextFrame.TextRange.Font
.Size = 12
.Name = "Bauhaus 93"
.Bold = False
.Color.RGB = RGB(255, 127, 255)
End With
End If
End If
Next shp
Next sld
End Sub
下面的代码应该可以工作。请注意,您的原始版本没有测试形状的“类型”,或者正如@Tim 指出的那样,您错过了“带有...”
此外,我对文本形状的测试的类型为 14,这是一个“占位符”。如果代码没有更改您想要更改的某些字体,您可能需要检查其他类型。
Option Explicit
Sub FontChange()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.Type = msoPlaceholder Then
With shp.TextFrame.TextRange.Font
.Size = 12
.Name = "Bauhaus 93"
.Bold = False
.Color.RGB = RGB(255, 127, 255)
End With
End If
Next shp
Next sld
结束子
我还想更改现有PowerPoint演示文稿中标题的字体。你知道这个的vba代码吗?