Import UserForms using VBA Code

xlhelp15

Board Regular
Joined
Sep 12, 2014
Messages
113
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hello Experts,

Is there a way to import UserForms (located in separate folder) when I open Excel file ?

Workbook_Open method can help but I'm not sure as how to call the Forms from that.

Your help is greatly appreciated !

Thanks.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
To import a userform, you can use the Import method of the VBComponents object. Note that you'll need to allow access to the VBA project...

Code:
File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Developer Macro Settings >> check/select Trust access to the VBA project object model

Here's an example...

Code:
    Dim path As String
    Dim fileName As String
    
    path = "c:\users\domenic\desktop\"
    
    fileName = "userform1.frm"
    
    ThisWorkbook.VBProject.VBComponents.Import path & fileName
 
Last edited:
Upvote 0
@ Domenic

If I recall correctly ... from Chip Pearson lessons ...

there is a need to include a check in Tools > References > Microsoft Visual Basic for Applications Extensibility ...

Right or Wrong ?
 
Upvote 0
@ Domenic

If I recall correctly ... from Chip Pearson lessons ...

there is a need to include a check in Tools > References > Microsoft Visual Basic for Applications Extensibility ...

Right or Wrong ?

You need to set a reference when using early binding. In my example, since I'm using late binding, no reference is needed.
 
Upvote 0
To import a userform, you can use the Import method of the VBComponents object. Note that you'll need to allow access to the VBA project...

Code:
File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Developer Macro Settings >> check/select Trust access to the VBA project object model

Here's an example...

Code:
    Dim path As String
    Dim fileName As String
    
    path = "c:\users\domenic\desktop\"
    
    fileName = "userform1.frm"
    
    ThisWorkbook.VBProject.VBComponents.Import path & fileName

Awesome ! - Thanks much Expert !
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top