TextBox in masterslides, change text

M

Magnen

Hi.

This is a PowerPoint question!

I am new to VBA, and now I am struggling with something that should be
simple.

I have a textBox located the footer in the master slide, and would like to
change the text of this textbox on all slides.

Let's say the name of the textbox is customFooter, how can i change the text
of this textbox on all slides?

Not like this:

For Each oSld In ActivePresentation.Slides
oSld.Master.Shapes("customFooter").TextFrame.TextRange.Text = msg
Next oSld

And not like this
For Each oSld In ActivePresentation.Slides
oSld.Shapes("customFooter").TextFrame.TextRange.Text = msg
Next oSld

Could somebody please help me :)

Thanks!

Magne
 
M

Magnen

I have also tried
ActivePresentation.SlideMaster.Shapes("customFooter").TextFrame.TextRange.Text , but then i get an error saying that this shape has no textframe
 
M

Magnen

Ok, so i figured out how to find the textbox or label from the master.

Dim lblFooter As Label
Set lblFooter =
ActivePresentation.SlideMaster.Shapes("lblFooter").OLEFormat.Object
lblFooter.Caption = "This is a test"

Now the text changes in the master, but only in the first master. How can i
make it change the labeltext on all open slides?
 
S

Steve Rindsberg

Ok, so i figured out how to find the textbox or label from the master.

Dim lblFooter As Label
Set lblFooter =
ActivePresentation.SlideMaster.Shapes("lblFooter").OLEFormat.Object
lblFooter.Caption = "This is a test"

Now the text changes in the master, but only in the first master. How can i
make it change the labeltext on all open slides?

What version of PowerPoint are you using?

And how did you add the text box to the master slide? Using the VB Controls
toolbox? Probably not a good idea unless you have a special reason for doing
it.

Instead, you'd want to add a normal PPT text box or shape.
 
M

Magnen

I would like it to work for both 2003 and 2007(I can test on both with
virtual pc)

Yes, I used the Vb Controls toolbox. How do i refer the textbox if I use a
normal PPT shape? By it's id, like ...Shape(2)...? What happens then if
somebody adds or removes a shape?

Now i tried a solution that overwrites the whole footer, works ok in 2007,
but in 2003 the new footer text comes on top of the old footer.

Thanks!
 
S

Steve Rindsberg

Magnen said:
I would like it to work for both 2003 and 2007(I can test on both with
virtual pc)

Yes, I used the Vb Controls toolbox. How do i refer the textbox if I use a
normal PPT shape? By it's id, like ...Shape(2)...? What happens then if
somebody adds or removes a shape?

The id changes. So what you do instead is look at all the shapes in the
shapes collection of the slide/master.

With each shape, if its .Type = 14 (placeholder) then
If its .PlaceholderFormat = (whatever the format is for the footer you're
after) then

You've found it


To set some part of it bold, you can use the .Characters method to return
just a portion of the text as a textrange. This example works on the
currently selected textbox, but you can adapt it as needed:

Dim oSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
With .TextFrame.TextRange
' Make the four characters beginning at position 5
' bold:
With .Characters(5, 4)
.Font.Bold = True
End With
End With
End With
 
M

Magnen

Thanks Steve :)

Steve Rindsberg said:
The id changes. So what you do instead is look at all the shapes in the
shapes collection of the slide/master.

With each shape, if its .Type = 14 (placeholder) then
If its .PlaceholderFormat = (whatever the format is for the footer you're
after) then

You've found it


To set some part of it bold, you can use the .Characters method to return
just a portion of the text as a textrange. This example works on the
currently selected textbox, but you can adapt it as needed:

Dim oSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh
With .TextFrame.TextRange
' Make the four characters beginning at position 5
' bold:
With .Characters(5, 4)
.Font.Bold = True
End With
End With
End With
 
M

Magnen

Some more questions :)

What if I have two placeholders of the same type? How can i determine wich
one i want to set the text in?

And is it possible to make a placeholder read only? (VBA can change the
text, but not the user?)

Thanks
 
S

Steve Rindsberg

What if I have two placeholders of the same type? How can i determine wich
one i want to set the text in?

If the template is one you've set up, you could apply tags to the
placeholders.

Or if you know the order or position or any other feature you could iterate
through the shapes collection and find the shape that's of the correct type
AND matches your criteria.
And is it possible to make a placeholder read only? (VBA can change the
text, but not the user?)

Not entirely. But if you can rely on the user having an add-in installed, an
event handler can trap the selection change event, determine wehther the
selected item is a "hands-off" one or not and if so, unselect it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top