UserForm1.Show does not work when open excel (excel is saved in xlsm-macro enabled)

allansanjan

New Member
Joined
Jan 4, 2022
Messages
5
Office Version
  1. 2007
Platform
  1. Windows
Hi guys, i cant get my userform auto-run/show when i open my excel file. Thanks in advance, i try to run it, all works fine.

My excel file is saved as .xlsm (enabled)

I have a Module1 (aznoltestmacro): i have done it and works perfectly,

UserForm1 codes are as below:
VBA Code:
Private Sub CommandButton1_Click()

UserForm1.Show

Call aznoltestmacro

MsgBox "Report Done!", , "Report Progress"
End Sub

Private Sub CommandButton2_Click()
Unload Me

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If you want it to happen when you open the workbook, you need to use the Workbook_Open event in the ThisWorkbook module, or use an Auto_Open routine in a normal module.
 
Upvote 0
To show the user form when you open the Excel-file, put UserForm1.Show in ThisWorkbook, Workbook_Open() sub. Paste this code in the ThisWorkbook object and it should work:

VBA Code:
Private Sub Workbook_Open()
    UserForm1.Show
End Sub


1641807636730.png
 
Upvote 0
To show the user form when you open the Excel-file, put UserForm1.Show in ThisWorkbook, Workbook_Open() sub. Paste this code in the ThisWorkbook object and it should work:

VBA Code:
Private Sub Workbook_Open()
    UserForm1.Show
End Sub


View attachment 54868

Hi Engberg,
I tried using your method placing the UserForm1.Show under Workbook_Open(), it doesnt work.. showed error 424,
hereby attached errors, Workbook_Open() code & my UserForm1 code
1641811942049.png
1641812100825.png
 
Upvote 0
If you want it to happen when you open the workbook, you need to use the Workbook_Open event in the ThisWorkbook module, or use an Auto_Open routine in a normal module.
Hi Rory,
Thanks, it works (userform pop out), but shows Run time error '1004' when i click on generate, can u teach me how and where did u input the code for the auto_open? i placed the auto_open under my module1,

VBA Code:
Private Sub Auto_Open()
UserForm1.Show
End Sub

Sub aznoltestmacro()
'this is where my macro starts
photos are as below for reference, thank you

1641812625480.png
1641812647570.png
1641812746315.png
 
Upvote 0
You don't appear to have an activeworkbook so you can't select a sheet in it. Are you trying to refer to a sheet in the personal macro workbook?
 
Upvote 0
Hi Engberg,
I tried using your method placing the UserForm1.Show under Workbook_Open(), it doesnt work.. showed error 424,
hereby attached errors, Workbook_Open() code & my UserForm1 code
View attachment 54877View attachment 54881

You need a user form named UserForm1 in the same project as the Workbook_Open, right now it looks like you're using two different projects/files.
 
Upvote 0
Solution
You need a user form named UserForm1 in the same project as the Workbook_Open, right now it looks like you're using two different projects/files.
[SOLVED]
Thanks Engberg! I recreated UserForm1 & Module1 under the same project files resulting the UserForm1 appears when i open the excel file. Thank you very much !

1641871313000.png
 
Upvote 0

Forum statistics

Threads
1,214,835
Messages
6,121,880
Members
449,057
Latest member
Moo4247

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