+ Reply to Thread
Results 1 to 12 of 12

Build userform on-the-fly

  1. #1
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107

    Build userform on-the-fly

    I'm trying to build an Excel userform on-the-fly.
    I wanted to put 2 columns side-by-side down the form.
    The first column is a label and the second column is a textbox.

    The label and textbox data are column A and column B in a worksheet.

    label1 textbox1
    label2 textbox2
    label2 textbox3
    label3 textbox4

    Any code or tips/pointers on this?

    Thanks,

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    This link might help

    http://j-walk.com/ss/excel/tips/tip76.htm

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Thanks - I'll have a look.

  4. #4
    Forum Contributor Gabor's Avatar
    Join Date
    02-15-2004
    Location
    Székesfehérvár, Hungary
    MS-Off Ver
    xl2016
    Posts
    226

    it depends

    The solution depends on what you want to do with the userform.
    Enter data to rows of a worksheet I suppose.
    In this case, try to copy the following code on the userform, place a Scrollbar1, a Spinbutton1, three CommandButtons on the form, plus your labels and TextBoxes as you described above.
    To load the UserForm you need an aditional macro on a normal modul.
    Cheers, Gabor

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Gabor,

    Thanks for the code snippet - a few mods and it was exactly what I wanted.

    Thank you.

  6. #6
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Though this is a good solution, it woudl be better if I could add the "label field" and the "text box field" programatically on the userform. The solution above makes me create the form ahead of time AND add all the fields ahead of time. If my data changes, I'll have to edit the userform.....

    I have some code that adds textfields to a userform within a frame - my issue with the code is "placement" of the field - it adds the fields directly on top of one another. I do not know how to place them correctly so they are in a column. There must be some x,y placement for the text box.

    One last item, I want to add Labels also, what is the name of that control type?

    Any help is appreciated.

    Thanks,

    Sub AddTextbox(box)
    Dim fr As Frame
    Dim Txt As Control
    Set Txt = Me.Frame1.Controls.Add("Forms.TextBox.1")

    Txt.Name = "Box" & box
    Txt.TabStop = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Of course, as soon as I ask for help I find out how to perform the task.
    Just use the properties of the object to arrange them accordingly.

    Sub AddTextbox(box)
    Dim fr As Frame
    Dim Txt As Control

    Set Txt = Me.Frame1.Controls.Add("Forms.TextBox.1")

    Txt.Top = Top
    Txt.Left = Left
    Txt.Width = Width
    Txt.Height = Height

    Txt.Name = "Box" & box
    Txt.TabStop = True
    End Sub

  8. #8
    Forum Contributor Gabor's Avatar
    Join Date
    02-15-2004
    Location
    Székesfehérvár, Hungary
    MS-Off Ver
    xl2016
    Posts
    226
    Building on your idea, or demand, maybe we should try to come up with a utility that asks the user to select what the type of the next control is to be (TextBox, Combobox, OptionButton, etc.) and so step-by-step the user would be able to build up the rough form that then could be easily customised further, re-sized, finalised within VBE.
    What do you think?
    Gabor

  9. #9
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Sounds like a great utility that could help many - maybe in a little bit though, I'm swamped at the moment...

  10. #10
    Registered User
    Join Date
    03-02-2007
    Posts
    1

    Question

    Hi, guys!

    Can UserForm be created only by code during macro excution, not with VB editor Isert->UserForm?

    Sorry for the stupid question, but I'm just starting to work with Excel VB.

    Yours, Boyko.

  11. #11
    Forum Contributor Gabor's Avatar
    Join Date
    02-15-2004
    Location
    Székesfehérvár, Hungary
    MS-Off Ver
    xl2016
    Posts
    226

    UserForm Wizzard

    UF-s are created in VBE primarily, however as posted by JWM6 it is possible to be done by code ??
    But since this is very cumbersum either ways a UF Wizzard would be of a great help.
    Does Anyone know such a feature somewhere on the net?

    Gabor

  12. #12
    Forum Contributor
    Join Date
    04-12-2006
    Location
    Morgan Hill CA
    Posts
    107
    Great queston, in my example, I already had the userform created. I have not investigated whether or not he userform can be created by VB code.

+ 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