Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to initialise a form, code what runs on form startup?

  Asked By: Seth    Date: Aug 16    Category: MS Office    Views: 1167
  

I have a form which is working, except i had a button on the form
that would open a file and read the first values in, having removed
this button, i want to have this happen the first time the form is
run, but im not sure what code runs on opening a form?

I have the 2 procedures below, but how do these get called?, do you
have to reference them elsewhere in the code (im guessing yes) or
does their name implicitly mean they get run on opening and closing
of the form???

Private Sub Form_Load()
Set xlwbook = xl.Workbooks.Open("d:\book1.xls")
Set xlsheet = xlwbook.Sheets.Item(1)
Myrow = 2
show_contact
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set xlwbook = Nothing
Set xl = Nothing
End Sub

In a C like language you have the main procedure, is VBA the same in
having key procedure names that work like this?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: William Evans     Answered On: Aug 16

There's a Workbook_Open event that you can put in the ThisWorkbook module.
There's also UserForm_Activate and UserForm_Initialize if you're using a
UserForm - I'm not sure yet. Let us know.
Here's a reference:
http://www.mrexcel.com/archive2/6800/7624.htm

 
Didn't find what you were looking for? Find more on How to initialise a form, code what runs on form startup? Or get search suggestion and latest updates.




Tagged: