On load or On open in Excel

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.

John SheehySystem Security ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ProfessorJimJamMicrosoft Excel ExpertCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John SheehySystem Security ManagerAuthor 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?

Rob HensonFinance AnalystCommented:
Add the code to the same script as opening the form.

Sub OpenForm()

next steps

End Sub

Open in new window

Rob HensonFinance AnalystCommented:
Just re-reading, if a button on the form is to be disabled straight away, why bother with it being there?
John SheehySystem Security ManagerAuthor 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.


And I disabled the buttons that needed to be.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.