Need VBA code to write text to a text box

  • Thread starter Thread starter Keith
  • Start date Start date
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
 
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
 
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 =
 
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
 
Back
Top