Question

I've just started learning programming in VBA for PowerPoint (about 30 mins ago). Could anyone help me with the following?:

I want a Macro that loops through all the slides' notes and changes the text to white

(I know there are non-macro alternatives to this but third-party software (Articulate) requires it be done via a Macro... long story).

This is what I have so far:

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

I get the error message "Run-time error: the specified value is out of range."

Thanks!

Joe

Was it helpful?

Solution

Welcome to the world of MS/VB's Famous Red Herrings (aka error messages).

The problem is this: some shapes don't have a text frame (the property of a shape that holds text) and even if a shape has a text frame, there may not be any text in it. Attempting to change text that isn't there, or text in a text frame that isn't there will throw an error.

Use this instead, which tests for text frame and if present, whether the text frame has text prior to changing the text in any way:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top