Solved

change font in PPT text box from VBA

Posted on 2010-09-24
3
3,087 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:Scott Helmers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
CRJ2000 earned 500 total points
ID: 33757324
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
 
LVL 30

Author Comment

by:Scott Helmers
ID: 33757516
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
 
LVL 6

Expert Comment

by:CRJ2000
ID: 33757570
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outline From PowerPoint 2010 it is possible to have shapes appear in front of video, in earlier versions video always played in front of other shapes. This means it is possible to have captions animated to appear in front of video. Users who h…
 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question