Need VBA code to write text to a text box

K

Keith

Hello,

I need to write some VBA code to put text into a large
number of preexisting text boxes on a powerpoint slide.
The process doesn't seem to be quite the same as working
with a form. Here are two questions.

First, how do I determine the name of a textbox that is
already on the form. (I'm ok with doing this in the
graphic interface -- I just can't seem to find a
properties list for the text boxes)

Second, once I know the name of the textbox, what
Powerpoint VBA code will write text to the box.

Thank you very much,

keith
 
P

PTT, Inc.

This macro will allow you to name your shapes instead of using the "generic"
ones PowerPoint calls them:

=====Start macro here======

Sub NameShape()
Dim Name$
On Error GoTo AbortNameShape

If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name

Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)

If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If
Exit Sub

AbortNameShape:
MsgBox Err.Description

End Sub

=======End macro Here=======

This line of code will assign a value to a text box named "Name1" on Slide 1
to some specific text. You can also assign it to a variable captured
elsewhere in your presentation:

ActivePresentation.Slides(1).Shapes("Name1").TextFrame.TextRange.Text =
"Your text"

You can also assign it to a variable captured elsewhere in your
presentation:

ActivePresentation.Slides(1).Shapes("Name1").TextFrame.TextRange.Text =
strYourString

Bill Foley, Microsoft MVP PowerPoint
www.pttinc.com
 
K

Keith

Hi Bill,
That's just what I needed to get started. Thank you.
keith

-----Original Message-----
This macro will allow you to name your shapes instead of using the "generic"
ones PowerPoint calls them:

=====Start macro here======

Sub NameShape()
Dim Name$
On Error GoTo AbortNameShape

If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name

Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)

If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If
Exit Sub

AbortNameShape:
MsgBox Err.Description

End Sub

=======End macro Here=======

This line of code will assign a value to a text box named "Name1" on Slide 1
to some specific text. You can also assign it to a variable captured
elsewhere in your presentation:

ActivePresentation.Slides(1).Shapes
("Name1").TextFrame.TextRange.Text =
"Your text"

You can also assign it to a variable captured elsewhere in your
presentation:

ActivePresentation.Slides(1).Shapes
("Name1").TextFrame.TextRange.Text =
 
Joined
Mar 21, 2011
Messages
1
Reaction score
0
Bill....!
you may have saved me...!

As you know the textboxes will not allow you to access properties and name them... Big hassle! and the Label controlBox will not allow you to (from design view) click and start typing text into them...Big hassle... I have two or three text boxes on each slide I would like to "Name" so I can access them in the VBA I am currently running, and I am playing around with the code you have listed above to try this out... any more suggestions would be greatly appreciated.


BTW - the main two text boxes would be named the same on almost every slide - Body_Txt and Instru_Txt
 

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