+ Reply to Thread
Results 1 to 10 of 10

Loop for creating textbox

  1. #1
    Registered User
    Join Date
    02-15-2009
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Loop for creating textbox

    Hi,

    I would be very thankfull if someone could tell me how can I create textbox by using loop. All thanks in advance for your input and help.

    Regards
    Last edited by murid; 05-20-2010 at 03:05 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Loop for creating textbox

    You don't need a loop to create a text box.
    Use the macro recorder and look at the code it gives when you place a TextBox.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Loop for creating textbox

    I am assuming you mean the graphical object textbox, rather than the textbox form control.

    You have not provided enough information to describe what you need but the code below will create multiple textboxes in a loop on a worksheet. The boxes will be 200 x 50 with vertical space of 10 in between.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Loop for creating textbox

    Quote Originally Posted by davegugg View Post
    You don't need a loop to create a text box.
    Use the macro recorder and look at the code it gives when you place a TextBox.
    Funny thing, that. I did that and it didn't generate any code. I created a textbox, added text, and then selected a cell. The only thing the macro recorder included was the cell selection.

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Loop for creating textbox

    Interesting, I did it before my first post in 07 and it gave me:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-15-2009
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Loop for creating textbox

    Hi Guys,

    Sorry for not providing more information on my request. Actually I'm trying to create comand button in form wil allow me to generate a textbox control (Forms) by using loop.

    Thanks
    Last edited by murid; 05-14-2010 at 03:28 PM.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Loop for creating textbox

    Quote Originally Posted by davegugg View Post
    Interesting, I did it before my first post in 07 and it gave me:
    I will just assume I had an ID-10-T error.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Loop for creating textbox

    Quote Originally Posted by murid View Post
    Hi Guys,

    Sorry for not providing more information on my request. Actually I'm trying to create comand button in form wil allow me to generate a textbox control (Forms) by using loop.

    Thanks
    This might be possible (I've never done it and I couldn't figure it out in 5 minutes) but I suspect there is a better way to do whatever it is you want to do. Dynamically modifying form elements is not an ideal programming practice, because it's tricky to reference them, and you can easily develop problems if you try to reference things before you create them. And what if you need to delete them later?

    What are you trying to do? You might be better off anticipating what text boxes you might need, then controlling whether they are visible or not based on user activity.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Loop for creating textbox

    Quote Originally Posted by davegugg View Post
    Interesting, I did it before my first post in 07 and it gave me:
    You created a textbox control. I created a textbox shape, as I had assumed in an earlier post. (However turns out the OP wants a control.) Nonetheless, it's odd that the macro recorder won't show creation of a textbox shape.

  10. #10
    Registered User
    Join Date
    02-15-2009
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Loop for creating textbox

    Salam,

    The solution below

    Private Sub CommandButton1_Click()

    Dim control1(4) As Control
    Dim y As Integer
    y = 0

    For i = 1 To 4
    Set control1(i) = UserForm1.Controls.Add("Forms.TextBox.1", "mytextbox", True)

    control1(i).Top = 100 + y
    control1(i).Left = 100
    control1(i).Width = 50
    control1(i).Height = 50

    y = y + 50

    Next i

    End Sub

+ 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