Chris1969
07-28-2022, 03:27 PM
Hello
I'm new to Powerpoint VBA, so apologies for what will seem like a basic question.
I have set-up a click button on a slide. When clicked it creates a text box, which I then want to able to manipulate in various ways e.g change the size and so on.
As far as I can tell, powerpoint assigns the new text box a name based on how many other controls have been created.For example it might be textbox4, textbox10 or textbox20. I would like to be able to identify the name of the box as soon as it is created, and then rename it so I can refer to it later in the code. I thought this would be straightforward, but I haven't been able to find a way of doing this.
I can refer to it by a shapes index number, but I think that relies on the new text box always having the same index.
Grateful for any advice/help. The code associated with the command click event is below. At the moment I am identifying the textbox name by changing the index in the final line until it gets to the right control, but that isn't a very satisfactory way of doing it.
Private Sub CmdTextMake_Click()
Set myDocument = ActivePresentation.Slides(3)
myDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=200, Height:=50).TextFrame.TextRange.Text = "Test Box"
MsgBox ("Active shape is " & myDocument.Shapes(2).Name)
End Sub
I'm new to Powerpoint VBA, so apologies for what will seem like a basic question.
I have set-up a click button on a slide. When clicked it creates a text box, which I then want to able to manipulate in various ways e.g change the size and so on.
As far as I can tell, powerpoint assigns the new text box a name based on how many other controls have been created.For example it might be textbox4, textbox10 or textbox20. I would like to be able to identify the name of the box as soon as it is created, and then rename it so I can refer to it later in the code. I thought this would be straightforward, but I haven't been able to find a way of doing this.
I can refer to it by a shapes index number, but I think that relies on the new text box always having the same index.
Grateful for any advice/help. The code associated with the command click event is below. At the moment I am identifying the textbox name by changing the index in the final line until it gets to the right control, but that isn't a very satisfactory way of doing it.
Private Sub CmdTextMake_Click()
Set myDocument = ActivePresentation.Slides(3)
myDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=200, Height:=50).TextFrame.TextRange.Text = "Test Box"
MsgBox ("Active shape is " & myDocument.Shapes(2).Name)
End Sub