disabling excel "on open" code?

E

Edward Scott

hi,

I would like my excel workbook to run some code whenever it is opened
by an automated process. I do not, however, want to run the code when a
person opens the workbook for viewing.

I am familiar with the Workbook_Open() Sub, but this code is run every
time the workbook is opened, which is not what I would like.

I have not yet found an elegant solution to this, so I thought I would
see if anyone out here had any suggestions. if there were some way to
activate particular macros when opening the document from the command
line (e.g. excel myworkbook.xls myMacro) that would be ideal, but I do
not know of a way to do this.

any suggestions, please let me know!
 
M

Michael Herzfeld

The Excel Application object has a property called UserControl. This
property returns true if the instance of Excel was started by a user and
it returns false if it was started via automation. Theoretically, your
Workbook_Open event could check this property and exit if its value is
true. This may not work for you though depending on how your users and
solutions use Excel. For example, if your automation solution always
creates its own instance of Excel, then it should work fine. But, if
your users run some other solution that starts up Excel
programmatically, and then they open your solution, UserControl would be
false, even though the user opened the workbook manually.

Other than this, I don't know of any way to accomplish what your looking
for (though theoretically, you might be able to make Win32 API calls
into the OLE automation code, but that would be really hard (if not
impossible) to do).

Michael Herzfeld
Office Programmability Test Team


-----Original Message-----
From: Edward Scott [mailto:[email protected]]
Posted At: Wednesday, October 05, 2005 1:04 PM
Posted To: microsoft.public.office.developer.vba
Conversation: disabling excel "on open" code?
Subject: disabling excel "on open" code?

hi,

I would like my excel workbook to run some code whenever it is opened
by an automated process. I do not, however, want to run the code when a
person opens the workbook for viewing.

I am familiar with the Workbook_Open() Sub, but this code is run every
time the workbook is opened, which is not what I would like.

I have not yet found an elegant solution to this, so I thought I would
see if anyone out here had any suggestions. if there were some way to
activate particular macros when opening the document from the command
line (e.g. excel myworkbook.xls myMacro) that would be ideal, but I do
not know of a way to do this.

any suggestions, please let me know!
 

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