Consulting

Results 1 to 3 of 3

Thread: Finding name of new text box

  1. #1

    Finding name of new text box

    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
    Last edited by Aussiebear; 07-29-2022 at 04:05 AM. Reason: Added code tags to supplied code

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You can set the name like this:

    Dim mydocument As Slide
    Set mydocument = ActivePresentation.Slides(3)
    With mydocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
        Left:=100, Top:=100, Width:=200, Height:=50)
        .TextFrame.TextRange.Text = "Test Box"
        .Name = " A_Unique_Name"
    End With
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Hi John

    That works. Thank you very much.

    Chris

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •