Hi,
There are 2 ways of doing this:-
Sub Aut
pen()
Msgbox "Hello"
End Sub
I think Aut
pen has been kept for backwards compatability. The preferred method (although there are only subtle differences) is to use the Workbook_Open event. Try this:-
Open the VB Editor and click Ctrl R to view the project explorer. You should see a treeview list showing all open workbooks and addins. Expand your workbook if it's not already expanded and double click the ThisWorkbook icon. From there you can program Excel to react to all sorts of events including Workbook_Open. From the left hand combobox at the top of the screen choose Workbook. This should automatically create a blank Workbook_Open procedure in which you can place your code. If you have a look at the right hand combobox you'll see the other events relating to a workbook i.e.
Activate - Occurs when the workbook is activated
AddinInstall - Occurs only when the workbook is saved as an add-in. It fires when the add-in is installed.
AddinUninstall - Occurs only when the workbook is saved as an add-in. It fires when the add-in is uninstalled.
BeforeClose - Occurs before the workbook is closed.
BeforePrint - Occurs before anything is printed.
BeforeSave - Occurs before the workbook is saved.
Deactivate - Occurs when the workbook is deactivated
NewSheet - Occurs when any sheet is added to the workbook.
Open - Occurs when the workbook is opened (executes before Aut
pen).
SheetActivate - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetBeforeDoubleClick - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetBeforeRightClick - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetCalculate - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetChange - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetDeactivate - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetFollowHyperlink - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
SheetSelectionChange - These events are similar to the events for an individual worksheet (see the Worksheet events sheet for explanations & examples). The only difference is that Excel provides an extra argument in the event procedure - Sh. This allows you to see which sheet the event occurred on.
WindowActivate - Occurs when any window in Excel is activated.
WindowDeactivate - Occurs when any window in Excel is deactivated.
WindowResize - Occurs when any window is resized.
HTH,
Dan
This message was edited by dk on 2002-05-08 05:54