Consulting

Results 1 to 7 of 7

Thread: Solved: trying to dynamically create a userform

  1. #1
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location

    Solved: trying to dynamically create a userform

    [VBA]Sub make_userform1()
    Dim TempForm
    Dim NewTextBox As MSForms.TextBox
    Dim NewLabel As MSForms.Label
    Dim NewCommandButton1 As MSForms.CommandButton
    Dim NewCommandButton2 As MSForms.CommandButton
    Dim x As Integer
    ' Hide VBE window to prevent screen flashing
    Application.VBE.MainWindow.Visible = False
    ' Create a Temp UserForm
    Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
    ' Add a Label
    Set NewLabel = TempForm.Designer.Controls.Add("forms.label.1")
    With NewLabel
    .Width = 140
    .Height = 20
    .Left = 48
    .Top = 10
    .Caption = "Lotus Notes Password"
    End With
    ' Add a TextBox
    Set NewTextBox = TempForm.Designer.Controls.Add("forms.textbox.1")
    With NewTextBox
    .PasswordChar = "*"
    .Width = 140
    .Height = 20
    .Left = 48
    .Top = 30
    End With
    ' Add the OK button
    Set NewCommandButton1 = TempForm.Designer.Controls.Add("forms.CommandButton.1")
    With NewCommandButton1
    .Caption = "OK"
    .Height = 18
    .Width = 66
    .Left = 126
    .Top = 80
    End With
    ' Add the Cancel button
    Set NewCommandButton2 = TempForm.Designer.Controls.Add("forms.CommandButton.1")
    With NewCommandButton2
    .Caption = "Cancel"
    .Height = 18
    .Width = 66
    .Left = 30
    .Top = 80
    End With
    End Sub
    [/VBA]

    getting compile error user type not defined on
    [VBA]Dim NewTextBox As MSForms.TextBox[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    missing reference, never mind
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    Why are you doing this like this if I may ask?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  4. #4
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    i'm using this userform basically as an inputbox but with the characters hidden to enter a password (PasswordChar = "*") which is a functionality the inputbox doesnt have, and i have to make this userform on multiple spreadsheets so i thought it would just save a lot of my time to automatically create it instead of playing with the stupid userform editor every time
    ------------------------------------------------
    Happy Coding my friends

  5. #5
    You do know you can export a form and import it in another project, or even simply drag the form in the Project explorer from one project to another?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I did something like that once and discovered that repeatedly creating and deleting a userform increased the file size with each creation and deletion. The file got pretty big.

  7. #7
    I'm not suggesting to do that repeatedly, just to insert an existing form into an existing project in order to prevent redoing the same work.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

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