Macro to open file bypasses Auto_Open

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
 
D

Dave Peterson

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
 
M

michdenis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top