Opening a form automatically with workbook

  • Thread starter Thread starter Xool
  • Start date Start date
X

Xool

Hi

Is there a way to make a form open automatically with the workbook, also is
there some code I can put on a close button that will close the workbook
too?

Cheers
 
Xool,

To auto load the form:
Open the VBA editor and doucle-click on This Workbook icon under your
workbook project in the project explorer window (left opart of screen). Now
go to the left of the two drop-down boxes just above the editor area, where
it reads (General), and select Workbook.You should automatyically get the
following procedure start and end lines:

Private Sub Workbook_Open()

End Sub

All you need to do is paste the following two lines of code in between, to
open the form:
Load FormName
FormName.Show
(changing FormName to the actual name of your form).

To close the workbook together with the form, put this code in the command
button's on_click event:
ActiveWorkbook.Close (you will be prompted to save changes, if any), or

ActiveWorkbook.Close True (save and close), or

ActiveWorkbook False (close without saving).

HTH,
Nikos
 
Thanks Nikos that works great ;-)

Nikos Yannacopoulos said:
Xool,

To auto load the form:
Open the VBA editor and doucle-click on This Workbook icon under your
workbook project in the project explorer window (left opart of screen). Now
go to the left of the two drop-down boxes just above the editor area, where
it reads (General), and select Workbook.You should automatyically get the
following procedure start and end lines:

Private Sub Workbook_Open()

End Sub

All you need to do is paste the following two lines of code in between, to
open the form:
Load FormName
FormName.Show
(changing FormName to the actual name of your form).

To close the workbook together with the form, put this code in the command
button's on_click event:
ActiveWorkbook.Close (you will be prompted to save changes, if any), or

ActiveWorkbook.Close True (save and close), or

ActiveWorkbook False (close without saving).

HTH,
Nikos
 
Back
Top