document open won't run

D

Dave

A maintenance app opens a Word document. Using the vbe, I created a
simple document_open sub in ThisDocument that will not run. It's my
understanding that regardless of whatever auto macros that may exist
in a template that this document is based on, a document_open sub
should run when the document is opened.

Notes: My macro security is set to low. In the vbe, a count of all
open documents returns 1 (looking for hidden documents that may be
affecting code). I ran through the CustomDocumentProperties and
BuiltinDocumentProperties in the debug window. There are no custom
properties; saw nothing built-ins to indicate code has been disabled.
The document is not protected (Tools>Protect Document is still
available; protectiontype = -1). A test document saved in my directory
will run the code.

There is no chance of knowing how the app opens the document, so how
can I determine if it is setting a property that disables code not
native to its template? All I want to do is automatically open a
linked file represented by an icon (inline shape??) in the document
when it opens. Help would be much appreciated. Thanks.
 
C

Cindy M.

Hi Dave,

It always helps us help you if you mention the VERSION of Word
involved.
All I want to do is automatically open a
linked file represented by an icon (inline shape??) in the document
when it opens.

I think this is the key point: AutoMacros do not run when accessing a
file that's embedded as an object. This is by-design.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
D

Dave

Hi Dave,

It always helps us help you if you mention the VERSION of Word
involved.


I think this is the key point: AutoMacros do not run when accessing a
file that's embedded as an object. This is by-design.

Cindy Meister
INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)

Right you are. v2002 on Windows XP Professional (probably SP3 but I'm
not at my work PC at the moment).
 
D

Dave

Right you are. v2002 on Windows XP Professional (probably SP3 but I'm
not at my work PC at the moment).

Just re-read what you wrote, and if I understand what you've said, you
missed the point, sorry to say. I dont' believe I said I was trying to
run an automacro when acting on a file. I said my understanding is
that no matter what, my code in the document_open event should run
when the document opens. That is by design, is it not? I confess I am
more familiar with Access VBA, but I believe an open event must fire
whenever the object opens. My suspicion is that some document property
has been set by the maintenance app on opening that doesn't allow this
to happen. As noted, the same code in a test document stored in my
network folder does run.
 
C

Cindy M.

Hi Dave,
Just re-read what you wrote, and if I understand what you've said, you
missed the point, sorry to say. I dont' believe I said I was trying to
run an automacro when acting on a file. I said my understanding is
that no matter what, my code in the document_open event should run
when the document opens. That is by design, is it not?

Could you please be more specific about how or where the document is
being opened? This is the "maintenance app" doing the opening?

Any code that opens a document can suppress "Auto macros". In all VBA
versions of the Word object model, this can be done with:

WordBasic.DisableAutomacros

And this also applies to the events.

In newer versions of Word (I can't remember whether this was introduced
in 2002 or 2003) there's also the Application.AutomationSecurity which
can enforce suppressing the execution of macros.

If this "Maintenance app" is using either of these, then the Open event
will not occur.

This is by design, as all kinds of problems can occur in a "batch
processing" application if macros were allowed to execute.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
D

Dave

Hi Dave,


Could you please be more specific about how or where the document is
being opened? This is the "maintenance app" doing the opening?

Any code that opens a document can suppress "Auto macros". In all VBA
versions of the Word object model, this can be done with:

    WordBasic.DisableAutomacros

And this also applies to the events.

In newer versions of Word (I can't remember whether this was introduced
in 2002 or 2003) there's also the Application.AutomationSecurity which
can enforce suppressing the execution of macros.

If this "Maintenance app" is using either of these, then the Open event
will not occur.

This is by design, as all kinds of problems can occur in a "batch
processing" application if macros were allowed to execute.

Cindy Meister
INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)

I think you must be correct in that the maintenance app is suppressing
the code; perhaps using one of the methods you've indicated. As I
mentioned, I'm more familiar with Access VBA (at least up to the 2002
model) and did not realize the open event could be prevented in Word.
It's all confusing because I've read that for 2002 (XP) and up, when
opening Word via automation, auto macros can be disabled but the
auto_open event for a document still runs. I'm going to drop the whole
thing for now as the effort is becoming more than the goal is worth
time-wise. Thanks for your help.
 
C

Cindy M.

Hi Dave,
It's all confusing because I've read that for 2002 (XP) and up, when
opening Word via automation, auto macros can be disabled but the
auto_open event for a document still runs

This is definitely not true.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
A

Ancient Brit

I'm coming in late to this thread, I know, but I have a similar problem.

Using Office Integration, in a networked environment SAP calls a user's
local copy of Winword.exe (workstation running Office 2003 under XP Pro) and
passes a document to it for Word to open.

In the document I have a Document_Open() macro in ThisDocument (as Dave
does), and it should run, but it doesn't. I'm trying to find out exactly how
SAP (using ABAP) calls Winword.exe to see whether I can fully understand
what's going on (or not, as is the case here).

It seems probable that Word is being invoked with at least one software
switch that may be preventing Document_Open() from triggering; the question
is, if it is, which switch is being used?

I read Cindy's comments about AutoMacros and it's true - Microsoft's own
notes say that for example if you call Word and use the /m switch, AutoMacros
are inhibited.

However, my own command-line tests have shown that /m does *not* inhibit
Document_Open() in ThisDocument from being triggered when SAP is not
involved. So I'm left wondering how SAP manages it. (Just FYI: the code in my
Document_Open() conducts a brief integrity check on the document in which it
resides to make sure that certain items are present, such as embedded LINK()
and DOCPROPERTY() fields).

Another (watermarking) application that runs under SAP and which also
invokes the same user's copy of Word and passes this document does allow
Document_Open() to execute, so it doesn't appear to be the case that it's an
issue caused by just any application calling Winword.exe.

There are multiple documents all with the same basic features
(Document_Open() in ThisDocument, among others) and they all have the same
behavior: they perform as expected when opened by a user running a local copy
of Word, and when opened by the watermarking app, but appear to be prevented
from executing Document_Open() when opened by Word run from SAP.

I've looked at the documented switches for Winword.exe and tried those that
seem relevant (/a for example, which doesn't impact Document_Open() when used
with Word run from a command line).

I tried using /m on the command line and Document_Open() stillexecutes; when
I use /m with another macro's name, Document_Open() executes first, followed
by the other macro - so /m seems to be working as expected (by me, anyway)
when Word is run by the user, and is probably not the switch being employed
by SAP (if indeed there is one).

So my problem is similar to Dave's: why isn't Word running Document_Open()
when called by SAP (my equivalent of the "maintenance program" Dave
mentions)? Are there undocumented switches for Winword.exe that not only
inhibit execution of AutoMacros but also manage to inhibit Document_Open() as
well?

Grateful for any thoughts, offline or on.

Regards,

Peter
--
 
D

Doug Robbins - Word MVP

What is the setting for the Macro Security?

If it is set to high, the macros in the document will be disabled without
any warning being given.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
A

Ancient Brit

Hi Doug

No, security is set to medium (so the user/maintainer can choose whether or
not to permit macros to run - this is an important aspect since it allows the
use of the shift key with 'Enable Macros' to bypass Document_Open yet still
keep all other user-initiated macros available).

I think I now have the answer though - and it may be the answer to Dave's
problem as well.

It's OLE. If a Word document is opened under OLE then Document_Open() does
not run. I've just spent some time testing this and it does seem to be the
cause of my problem, at any rate.

As a way of modeling what I think is happening, I modified my Word
document's Document_Open() so that it announces its execution through a
dialog (just a simple MSGBOX "Running Document_Open").

I then created a blank Excel workbook and inserted that Word document into a
worksheet as a linked object.

When the Excel document is opened and I open the embedded Word object,
Document_Open() doesn't run - which is exactly what's been happening when the
document is opened from within SAP. (The SAP aspect is something of a black
box and outside my sphere of influence; other than the call is almost
certainly made using ABAP, I have no information).

When the third party watermarking app runs, it's clearly not using OLE (it
doesn't need to modify the original document - it simply adds a watermark as
it creates a PDF which is the final stage of output for review (this is a
regulated environment so printed copies are trusted within well-defined
limits)), so that explains the anomalous behavior.

I don't know much about OLE and the method it uses to access Winword.exe,
but I'd speculate that it's simply using an API to directly call for want of
a better term 'the Word engine', rather than executing the .exe file itself.
I'd expect that approach would bypass any macro-opening behavior associated
with running Winword.exe.

In Dave's case, I don't know whether he can tell if OLE is involved, but it
could explain why his maintenance app is able to suppress execution of
Document_Open().

The next step is to see whether there is a way to get even an OLE-triggered
Word engine to run Document_Open() - or some undocumented command that would
allow an auto-macro-like trigger to function.

Grateful thanks to all,

Peter
 

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