Autoexec macro question

Robin

New Member
Joined
Feb 26, 2002
Messages
16
Hi guys,

Is there an euivalent to the Access Autoexec macro in Excel? Eg, one that runs automatically when you run Excel. I've tried creating one called Autoexec but that doesn't work.

Thanks in advance,

Robin
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,

There are 2 ways of doing this:-

Sub Auto_Open()
Msgbox "Hello"
End Sub

I think Auto_Open 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 Auto_Open).
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
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top