change font in PPT text box from VBA

I'm trying to change the font of an empty text placeholder on a slide from VBA. Sounds simple enough but apparently I haven't got the right object or something...

I've tried a variety of approaches including the ones shown below. Test1 (textrange object) and Test2 (shape object) didn't work. Then I used the macro recorder to record the UI actions that do accomplish what I want. However, replaying this macro does *not* cause the correct result.

What am I missing?

Thanks
Sub test1()
    Dim tr As TextRange
    
    Set tr = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
    tr.Font.Size = 18  
End Sub
Sub test2()
    Dim shp As Shape
    
    Set shp = ActivePresentation.Slides(1).Shapes(2)
    shp.Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Font.Size = 18
End Sub
Sub Macro12()
    ActiveWindow.Selection.SlideRange.Shapes("Rectangle 21").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Font.Size = 18
End Sub

Open in new window

LVL 31
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAsked:
Who is Participating?
 
CRJ2000Connect With a Mentor Commented:
Hmm. This is odd. Your Test1 is correct, but PowerPoint doesn't behave very nicely. Try the following:

Sub test1()
    Dim tr As TextRange
   
    Set tr = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
    tr.Text = "Test"
    tr.Font.Size = 18
    tr.Text = "" 
End Sub

0
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Glad to know I'm not completely crazy...

Thanks for the suggestion. It did work! So PPT doesn't like setting fonts on empty textranges from code even though it works in the UI...
0
 
CRJ2000Commented:
Very, strange, isn't it? Add it to the list of oddities that one needs to track to make VBA do what you think it should do in the Office products. :)
0
All Courses

From novice to tech pro — start learning today.