+ Reply to Thread
Results 1 to 4 of 4

Add a textbox using VBA

  1. #1
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Add a textbox using VBA

    Is there any VBA code that can add a textbox to a worksheet?

    I have a worksheet, and if certain conditions are met, I would like a textbox containing certain information to be added to the worksheet. I do not want the information itself to be enterred into the cells, but I would like it to be visible in this textbox when I print out the report.

    Can anyone guide me in the right direction?

    Thank you.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello BigBas,

    Here is macro to insert a TextBox on the ActiveSheet at cell "E3". You can change the size properties to what you need.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    Thanks Leith. Works as needed. But how do I populate the textbox with text using VBA. I assume it would be code like : textbox1.text = "Insert Text"

    But, how do I know what the name of the textbox is? Thanks in advance for the help.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello BigBas,

    I thought about that after I posted the code. I have added a Public variable to hold the name of the TextBox. All the code goes in the same module.
    Please Login or Register  to view this content.
    When referencing OLE Objects, you should qualify them with the Worksheet the object belongs to. Otherwise, VBA assumes you mean the ActiveSheet, and if there are no OLE Objects you get an error.

    Inserting Text Example
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1