Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing Text of Textbox (03)

    How does one change the text of a textbox (drawing object) without selecting the object itself?

    The macro recorder reflect the object as being selected. Take away the selection and the code fails.

    Thanks,
    John

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Changing Text of Textbox (03)

    Something like (change name as needed)

    ActiveSheet.Shapes("Text Box 1").TextFrame.Characters.Text = "This is Text to add"

    Steve

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Changing Text of Textbox (03)

    Click on the border of the text box.
    Switch to the Visual Basic Editor.
    Type the following in the Immediate window, then press Enter:

    ? Selection.Name

    You'll see something like Text Box 3.
    You can use this name to change the text of the text box using code without selecting the text box:

    ActiveSheet.Shapes("Text Box 3").TextFrame.Characters.Text = "John Stevens"

    Alternatively, you can refer to the text box by its index number in the collection of Shapes:

    ActiveSheet.Shapes(2).TextFrame.Characters.Text = "Woody's Lounge"

    Of course, you can replace ActiveSheet with a reference to a named sheet, or with the name of a variable of type Worksheet.

Posting Permissions

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