Run macro on opening workbook


Posted by Lewis on December 07, 2001 2:31 AM

Simple question which my searches through the VBA Help have failed to resolve.

How do you run a macro when you open the workbook?

Thanks in advance

Lewis

Posted by TDK on December 07, 2001 3:06 AM

Bit of VB needed:

Private Sub Workbook_Open()

"your code here"

End Sub

Posted by Lewis on December 07, 2001 3:52 AM


If I try to enter the name workbook_Open() I get an error message to say the name is not valid?

Lewis

Posted by Mudface on December 07, 2001 3:59 AM

Go to the VB editor, double-click on the 'ThisWorkbook' entry on the left hand side of the screen. On the right-hand side in the code editor bit, change from General to Workbook. This will automatically create the Workbook_Open() sub. Note that you can choose other Workbook events other than 'Open' too by clicking the arrow to the right of the box displaying 'Open'.



Posted by Colo on December 07, 2001 4:00 AM

Hi.
:If I try to enter the name workbook_Open() I get an error message to say the name is not valid?
if you use "workbook_Open()" You have to write on "Thisworkbook" module.

or it does not work try this

Sub Auto_Open()
"your code here"
End sub