Macro to open file bypasses Auto_Open

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I have the following code.

Workbooks.Open Filename:=vOpen, UpdateLinks:=3

But when I run this it does not process the macro Auto_Open.

Why is this?

I would like for code to run on the opening of the file regardless of how
the user opened it. (ie. If they opened it using File / Open on the menu
then yes, the Auto_Open would run. But I also want code to run even if
they write their own macro to open it.)

Thank you,

Steven
 
That's the way excel was designed to work.

Lots of times, developers want to open the workbook without having that macro
run (maybe they're automating something and want to avoid some msgbox/inputbox
in that auto_open procedure.

But MS did give you a way to run that procedure.

dim wkbk as workbook
set wkbk = workbooks.open(filename:=vopen, updatelinks:=3)
wkbk.RunAutoMacros which:=xlAutoOpen

(there are other options for the Which parm, too--see VBA's help for
RunAutoMacros).

Interestly (well, maybe <bg>), MS does the opposite with the Workbook_Open
event. That runs unless you stop it.

dim wkbk as workbook
application.enableevents = false
set wkbk = workbooks.open(filename:=vopen, updatelinks:=3)
application.enableevents = true
 
Hi,

a simple example of a code you could use
in your file to open

http://cjoint.com/?bjfjH1n6v0




"Steven" <[email protected]> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
I have the following code.

Workbooks.Open Filename:=vOpen, UpdateLinks:=3

But when I run this it does not process the macro Auto_Open.

Why is this?

I would like for code to run on the opening of the file regardless of how
the user opened it. (ie. If they opened it using File / Open on the menu
then yes, the Auto_Open would run. But I also want code to run even if
they write their own macro to open it.)

Thank you,

Steven
 
Back
Top