PDA

View Full Version : Solved: Change Powerpoint Textboxes



jay raskol
08-02-2007, 11:23 PM
Hi,

with the great help of the experts here I have managed to keep my first ever VBA project bouncing along. I have managed to dynamically update multiple powerpoint datasheets in multiple presentations using data from my excel worksheets and am now trying to do the same with textboxes. I am looking for an example of how to alter the text to a new string or value. It can be assumed I already have powerpoint , the presentation, and the slide in question active. I have managed to make a button to change the name of the textboxes from their defaults so I can track them more easily in my code but I can't find the appropriate syntax to address textboxes on a given slide using the name. Also, when updating graphs I was just looping through all shapes on a slide. But if I can name the graph objects can I also refer to these more simply by name rather than checking which type of object they are?

Regards all,
Jason

rory
08-03-2007, 03:35 AM
You can use:
Activepresentation.Slides(1).Shapes("Text Box 4").TextFrame.TextRange.Text = "new text"

to change the text. You should also be able to refer to charts by the name of the shape.

Regards,
Rory

jay raskol
08-05-2007, 06:55 PM
Thanks Rory,
I used this with a slight variation, as I had to refer to the application object variable declared (oPPTApp), and it worked fine.

oPPTApp.ActivePresentation.Slides(1).Shapes("Title").TextFrame.TextRange.Text = sName

I also found an additional vba macro, and attached to a button, to change the name of the textbox to something more useful than the default. This seems very handy for coding such things.


Sub ChangeName()
On Error GoTo ChangeNameError
' Is an object selected?
If ActiveWindow.Selection.Type <> 0 Then
' Change the object's name
ActiveWindow.Selection.ShapeRange.Name = InputBox("Please enter object name", "Rename Object", ActiveWindow.Selection.ShapeRange.Name)
Else
'Change the slide's name
ActiveWindow.Selection.SlideRange.Name = InputBox("Please enter slide name", "Rename Object", ActiveWindow.Selection.SlideRange.Name)
End If
Exit Sub
ChangeNameError:
' This removes the problem if they press cancel.
End Sub

Thanks again,