Results 1 to 3 of 3

Programatically cretae and initialize a userform

Threaded View

  1. #1
    Registered User
    Join Date
    06-03-2017
    Location
    portugal
    MS-Off Ver
    2016
    Posts
    1

    Cool Programatically cretae and initialize a userform

    Hello Everybody

    I'm trying to create and initialize an userform dynamically. I can create it but not initialize. I'm publishing the code that I'm using
    the problem occurs when in Userform_Initialize it doesn't recognize the variable FormName

    Some ideas

    Thanks


    Option Explicit
    Public FormName As String
    
    Sub MakeForm()
        Dim TempForm As Object ' VBComponent
        
        Dim NewButton As MSForms.CommandButton
        Dim TextLocation As Integer
    '   ** Additional variable
        Dim X As Integer
    
        'Locks Excel spreadsheet and speeds up form processing
        Application.VBE.MainWindow.Visible = False
        Application.ScreenUpdating = False
        
    '   Create the UserForm
        Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
        
        'Set Properties for TempForm
        With TempForm
             .Properties("caption") = "Menu Principal Louro e Rosmaninho"
             .Properties("Width") = Application.Width
             .Properties("Height") = Application.Height
    
            .Properties("Left") = Application.Left
        End With
        FormName = TempForm.Name
    With TempForm.CodeModule
    '   ** Delete This: TextLocation = .CreateEventProc("Click","CommandButton1")
    
    '   ** Add/change next 5 lines
    '       This code adds the commands/event handlers to the form
    
           X = .CountOfLines
            .InsertLines X + 1, "Public Sub Userform_Initialize()"
            .InsertLines X + 2, "Dim filename As String"
                .InsertLines X + 3, "MsgBox FormName"
            .InsertLines X + 4, "filename = ""C:\Pessoal\Investimento Mercearia Prata\Excel Tables Files\Imagens\Fundo-Menu-Principal-Mercearia-da-Prata.jpg"""
            .InsertLines X + 5, "FormName.Picture = LoadPicture(filename)"
            .InsertLines X + 6, "FormName.PictureSizeMode = fmPictureSizeModeStretch"
           .InsertLines X + 6, "MsgBox 2 & FormName"
            .InsertLines X + 7, "End Sub"
          
        End With
    
    '   Show the form
    
    
    '    VBA.UserForms.Add(FormName).Show
    
    VBA.UserForms.Add(FormName).Show
    Last edited by Glenn Kennedy; 07-08-2021 at 03:21 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform will not initialize
    By opusarlo in forum Excel General
    Replies: 3
    Last Post: 12-13-2016, 04:21 PM
  2. How to use the UserForm Initialize event to Initialize 3 listboxes in the same userform
    By Pimp_mentality in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-16-2016, 02:59 PM
  3. Userform - help with initialize
    By Macster in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-23-2009, 05:40 AM
  4. [SOLVED] userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2006, 06:20 PM
  5. [SOLVED] userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2006, 05:40 PM
  6. userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2006, 05:35 PM
  7. initialize userform, using a sub
    By natanz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-22-2005, 01:35 AM

Tags for this Thread

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