On load or On open in Excel

John Sheehy
John Sheehy used Ask the Experts™
on
So I have this form that is displayed in one my excel workbooks.  I need a few lines of code to run right when the form pop ups.  I normally work in access and would sue an On_Load or On_Open event, but excel does not have that.

What can I use instead to run these commands when the form opens.

Thanks
John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Microsoft Excel Expert
Top Expert 2014
Commented:
I am not sure if i understood your question correctly,

when you add a userform then you double click on it to go its code page



Private Sub UserForm_Initialize()
MsgBox "macro started"
End Sub

Open in new window

Private Sub UserForm_Deactivate()
your macro
End Sub

Open in new window

John SheehySystem Security Manager

Author

Commented:
I have a button on a worksheet.  The user clicks the button and opens a user form.

When that user form opens I need certain button on it to be disabled right off the bat.

Is that better?

John
Rob HensonFinance Analyst

Commented:
Add the code to the same script as opening the form.

Sub OpenForm()

UserForm1.Show
next steps

End Sub

Open in new window

Rob HensonFinance Analyst

Commented:
Just re-reading, if a button on the form is to be disabled straight away, why bother with it being there?
John SheehySystem Security Manager

Author

Commented:
The button will enable itself once one of the lines on the form is filled.  It shows the user their options but let's them know required information is missing.  Where I work we need to think of every possibly question a user could have.

I did try your suggestion but it did nothing until the form was no longer showing and then it proceeded to the next line.

But this did work.

UserForm_Initialize()

And I disabled the buttons that needed to be.

Thanks
John

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial