ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to open file bypasses Auto_Open (https://www.excelbanter.com/excel-programming/438171-macro-open-file-bypasses-auto_open.html)

steven

Macro to open file bypasses Auto_Open
 
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

Dave Peterson

Macro to open file bypasses Auto_Open
 
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



Steven wrote:

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


--

Dave Peterson

steven

Macro to open file bypasses Auto_Open
 

Never mind. I think this was an EnableEvents issue.

Regards,

Steven

"Steven" wrote:

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


michdenis

Macro to open file bypasses Auto_Open
 
Hi,

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

http://cjoint.com/?bjfjH1n6v0




"Steven" a écrit dans le message de groupe de
discussion : ...
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


Dave Peterson

Macro to open file bypasses Auto_Open
 
Not if you were really using Auto_Open.

Steven wrote:

Never mind. I think this was an EnableEvents issue.

Regards,

Steven

"Steven" wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 07:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com