批量设置PowerPoint字体及行间距——VBA宏
时间: 2023-07-31 16:05:35 浏览: 570
好的,下面是针对批量设置PowerPoint字体及行间距的VBA宏代码:
```
Sub BatchSetFontAndLineSpacing()
Dim sld As Slide
Dim shp As Shape
Dim fontName As String
Dim fontSize As Integer
Dim lineSpacing As Single
'设置要应用的字体、字号和行间距
fontName = "微软雅黑"
fontSize = 16
lineSpacing = 1.5
'遍历每一页幻灯片
For Each sld In ActivePresentation.Slides
'遍历每个形状
For Each shp In sld.Shapes
'判断形状是否为文本框
If shp.HasTextFrame Then
'设置字体、字号和行间距
shp.TextFrame.TextRange.Font.Name = fontName
shp.TextFrame.TextRange.Font.Size = fontSize
shp.TextFrame.TextRange.ParagraphFormat.LineSpacingRule = msoLineSpaceAtLeast
shp.TextFrame.TextRange.ParagraphFormat.LineSpacing = lineSpacing * fontSize
End If
Next shp
Next sld
End Sub
```
使用方法:
1. 打开PowerPoint文件,按下Alt+F11,打开VBA编辑器;
2. 在VBA编辑器中,按下Ctrl+R,打开“Microsoft Visual Basic for Applications”窗口;
3. 将上述代码复制粘贴到窗口中;
4. 修改代码中的字体、字号和行间距为自己想要的值;
5. 按下F5执行代码,等待执行完毕即可。
需要注意的是,该VBA宏会将每一页幻灯片中的所有文本框的字体、字号和行间距都设置为相同的值。如果需要针对某些文本框进行单独设置,可以在代码中添加相应的判断条件。
阅读全文
相关推荐

















