Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Autoexec macro question

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    16
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •