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.

Thanks
John
John SheehySecurity AnalystAsked:
Who is Participating?
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.

ProfessorJimJamCommented:
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

0

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 SheehySecurity AnalystAuthor 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
0
Rob HensonFinance AnalystCommented:
Add the code to the same script as opening the form.

Sub OpenForm()

UserForm1.Show
next steps

End Sub

Open in new window

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.