Powerpoint的VBA宏可以更改Notes颜色

时间:2014-02-12 12:11:58

标签: vba powerpoint powerpoint-vba

我刚刚开始在VBA for PowerPoint中学习编程(约30分钟前)。任何人都可以帮助我以下吗?:

我想要一个宏来循环播放所有幻灯片'注释并将文本更改为白色

(我知道有非宏的替代方案,但第三方软件(Articulate)要求通过宏...长篇故事来完成。

这是我到目前为止所做的:

Sub changenotestowhite()
   Dim osld As Slide
   Dim oshp As Shape
   Dim strNotes As String
   For Each osld In ActivePresentation.Slides
      For Each oshp In osld.NotesPage.Shapes
         oshp.TextFrame.TextRange.Font.Color = vbWhite
      Next oshp
   Next osld
End Sub

我收到错误消息"运行时错误:指定的值超出范围。"

谢谢!

1 个答案:

答案 0 :(得分:0)

欢迎来到MS / VB的着名红色鲱鱼世界(又名错误信息)。

问题在于:某些形状没有文本框架(包含文本的形状的属性),即使形状具有文本框架,也可能没有任何文本。尝试更改不存在的文本或文本框架中不存在的文本将导致错误。

使用此代码,对文本框架进行测试,如果存在,则在以任何方式更改文本之前文本框架是否包含文本:

Sub changenotestowhite()
   Dim osld As Slide
   Dim oshp As Shape
   Dim strNotes As String
   For Each osld In ActivePresentation.Slides
      For Each oshp In osld.NotesPage.Shapes
        If oshp.HasTextFrame Then
        If oshp.TextFrame.HasText Then
         oshp.TextFrame.TextRange.Font.Color = vbWhite
         End If
         End If
      Next oshp
   Next osld
End Sub