小学生桌子高度:批量修改ppt中所有字的字体颜色

来源:百度文库 编辑:中财网 时间:2024/04/28 01:22:33

批量修改ppt中所有字的字体颜色

本篇文章将会告诉你,怎样利用office中的宏,批量修改PPT中所有字的字体、颜色、字号、背景等。   今天我一朋友来找我,说他想打印一个PPT,于是想把它变成白底黑字,并保存。我翻了半天,发现office本身是没有这个功能的,于是我终于找到了一个方法来实现。(以下演示版本为Office2007,其他版本的类似)


1、背景模板的处理

打开幻灯片母板,选择插入新的幻灯片母板,得到一个空白的母板。

然后删除掉原来的母板。还原普通视图,这样就去掉了幻灯片的模板背景。

2、利用宏批量改变字体

在视图中选择宏(早期版本可能要在插入中找),输入任意的宏名,点击创建。

  在新代码窗口中,删除原来的内容,并复制以下内容,然后运行宏(若不能运行,请看下面)。此时工作已经全部完成了。

Sub myfont()

Dim oShape As Shape
Dim oSlide As Slide
Dim oTxtRange As TextRange
On Error Resume Next ' 之后的代码就算出错也会继续执行

For Each oSlide In ActivePresentation . Slides
oSlide . FollowMasterBackground = msoTrue ' 使用幻灯片母版背景
For Each oShape In oSlide . Shapes

' 文本框字体设置
With oShape . TextFrame . TextRange . Font
' .Name = "宋体"
' .Size = 20
. Color . RGB = RGB(Red : = 0 , Green : = 0 , Blue : = 0 )
' .Bold = msoFalse '粗
. Italic = msoFalse '
. Underline = msoFalse ' 下划线
End With
oShape . Fill . Background ' 文本框背景色用幻灯背景填充
oShape . TextFrame . TextRange . IndentLevel = 0

' 表格字体设置
oShape . Table . Background . Fill . BackColor . RGB = RGB(Red : = 255 , Green : = 255 , Blue : = 255 ) ' 底色
For i = 1 To oShape . Table . Rows . Count
For j = 1 To oShape . Table . Columns . Count
oShape . Table . Cell(i, j) . Shape . Fill . BackColor . RGB = RGB(Red : = 255 , Green : = 255 , Blue : = 255 )
With oShape . Table . Cell(i, j) . Shape . TextFrame . TextRange . Font
' .Name = "宋体"
' .Size = 20
. Color . RGB = RGB(Red : = 0 , Green : = 0 , Blue : = 0 )
' .Bold = msoFalse '粗
. Italic = msoFalse '
. Underline = msoFalse ' 下划线
End With
Next j
Next i

Next
Next

End Sub

 

注意: 1.以上代码相应部分可以根据需要自行修改 2.运行后可能仍有部分是彩色。如:表格的内嵌,项目符号编号,图片等。前两项仍然需要手动修改颜色。

不能运行宏的解决办法

点击左上角菜单,选择PPT选项

信任中心->宏设置,选中启用所有和信任对VBA的访问,确定。然后重启PPT即可。