Auto_Open Vs Workbook_open

  • Thread starter Thread starter Soniya
  • Start date Start date
S

Soniya

Hi all,

what difference it makes having code under Auto_open or
under Workbook_open

TIA

Soniya
 
Soniya,

Workbook_Open is an "event" that "fires" whenever a workbook
is opened.
Auto_Open is a "sub" that Excel recognizes and runs when a workbook
is opened.
The main difference is that the Workbook_Open "event" fires whether
the workbook is opened manually or via code (from another workbook).
The Auto_Open will only run when the workbook is opened manually.

John
 
Hi Soniya..


workbook_open runs first and auto_open next

When you open a book manually:
BOTH will run UNLESS you keep SHIFT key pressed.

When you open a book with vba:
the auto_open WILL NOT run UNLESS you add the line (after open)
ActiveWorkbook.RunAutoMacros xlAutoOpen

the workbook event code WILL run UNLESS you add (before open)
Application.EnableEvents = FALSE

I think Auto_open was left in for backward compatibility with excel4
macros. Personally I'd use Workbook_Open


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
I Have used
Private Sub Workbook_Open()
Application.OnKey "+^H", "Get_Cursor_Pos"
Application.OnKey "+^J", "ExitClick"
End Sub
In one case and setting up the Macro Key in Excel Macros - Options in another case.
The code is (summary)
Get_CursorPositon
...
SelecThis = True
Do While SelecThis
...
DoEvents
Loop
End Sub
Sub ExitClick()
SelectThis = False
DoEvents
End Sub
The issue is that using the OnKey approach, ExitClick is not Called if Get_Curso_Position is running (BTW if Get_Cursor_Position is not running, ExitClick will be called) whereas when using the Excel- Options approach it is called.
Please Help me understand this.
Further: I notice I didn't put a DoEvents in the ExitClick() and have now shown it correctly, and
I see that if I run ExitClick first, Get_Cursor_Position will not run in response to Ctrl-Shift-H
Is something other than Exit Sub needed to allow some other Key based Macro call?

I now see that the same problem exists with either method of setting up the Key.
Hmmm ! ?
 
Last edited:
Back
Top