Which Event to Execute Right After Document Loaded ?

A

aushknotes

If I want to intercept the processing right after a document is fully loaded
(opened), which event shall I put my codes in ? I tried Document_Open &
Autoexec but seems like they are executed before the document is loaded? Is
there any write-up on MVP regarding the sequence how Word starts up? Many
thanks!
 
C

Cindy M.

Hi =?Utf-8?B?YXVzaGtub3Rlcw==?=,
If I want to intercept the processing right after a document is fully loaded
(opened), which event shall I put my codes in ? I tried Document_Open &
Autoexec but seems like they are executed before the document is loaded?
AutoExec runs when Word is first started. AutoOpen is the macro that runs
(besides the Document_Open event) when a document is opened.

What kind of problem are you having, that the code executed in these is "too
soon"? And in what version of Word?

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

aushknotes

Hi Cindy,

I'm using Word 2003. I'm planning to put in some sort of preventive health
check on the document once it is loaded. I guess a good example could be the
Char Styles routine that you developed some time back. This is still a very
very annoying issue indeed.

Cheers,
 
C

Cindy M.

Hi =?Utf-8?B?YXVzaGtub3Rlcw==?=,
I'm using Word 2003. I'm planning to put in some sort of preventive health
check on the document once it is loaded. I guess a good example could be the
Char Styles routine that you developed some time back. This is still a very
very annoying issue indeed.
As far as I know (and in my experience) the document should be available when
AutoOpen executes.

Sub AutoOpen
Dim doc as Word.Document

Set doc = ActiveDocument
'Do stuff with it here
End Sub

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

aushknotes

Thanks, Cindy. I'll try with your suggestion. Today I used VBA in word to
open another existing doc & stepped thru with the debugger. It showed that
Normal.dot was opened & Document_Open() was executed. I put a stop statement
in this and save it. Then opened the same document from document management
system (PC-DOC and iManage), but it did not stop in Normal.dot as expected.
Any idea?
 
C

Cindy M.

Hi =?Utf-8?B?YXVzaGtub3Rlcw==?=,
I'll try with your suggestion. Today I used VBA in word to
open another existing doc & stepped thru with the debugger. It showed that
Normal.dot was opened & Document_Open() was executed. I put a stop statement
in this and save it. Then opened the same document from document management
system (PC-DOC and iManage), but it did not stop in Normal.dot as expected.
Let's start over. Please lay out exactly what you need to do. I understood you
wanted to work with a document when that document opens. The AutoOpen macro
would be in that document.

It sounds to me as if you're trying to pick up *all* documents that open?

And as soon as you have other software in the mix, things can behave very
differently. I think you first have to find out how these document management
systems affect Word. If, for example, they're picking up the DocumentOpen event
at the application level that could change how things work. I have no
experience with this software - you may have to work with people who know what
that software does and how you have to interact with it...

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

aushknotes

Let's start over again with a simple scenario. Forget about the document
management system for the time-being and let's start with Word 2003 only.

Now my first objective is to fire off a macro, right after an existing word
document is opened by whatever means, double-click or right-click open from
windows explorer, or File Open from within Word 2003. This could possibly be
achieved by implementing a macro in AutoOpen(0 or Document_Open(), right?

Now assume the document may or may not be attached to a template. In
addition, a number of templates, let say 10, will also be loaded from the
default StartUp folder. OK?

This is the scenario I would like to simulate.

Many thanks,
 
C

Cindy M.

Hi =?Utf-8?B?YXVzaGtub3Rlcw==?=,
Let's start over again with a simple scenario. Forget about the document
management system for the time-being and let's start with Word 2003 only.
If the document management system is installed and interfering with how Word
functions, you can't ignore it. I'm afraid that's the way it is. And such a
tool can interfere with how Word functions, so you may not see what I see if
it's present on your machine.
Now my first objective is to fire off a macro, right after an existing word
document is opened by whatever means, double-click or right-click open from
windows explorer, or File Open from within Word 2003. This could possibly be
achieved by implementing a macro in AutoOpen(0 or Document_Open(), right?

Now assume the document may or may not be attached to a template. In
addition, a number of templates, let say 10, will also be loaded from the
default StartUp folder. OK?

This is the scenario I would like to simulate.
So I don't understand your question: what do you want to simulate?

AutoOpen in normal.dot will fire when a document is opened. The attached
template will also be loaded.

But the templates in the Startup folder:

1. Will be loaded only when Word starts (not every time a document is opened)
2. Will never run an AutoOpen (or AutoNew) macro they may contain

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 :)
 
G

Gordon Bentley-Mix

It's probably the DMS integration that's suppressing the execution of the
AutoOpen macro - kind of like setting macro security in Word to 'High'. In a
DMS like iManage the integration is usually provided through a global
template(called "iManO2K" in most cases) which does all sorts of stuff like
intercept the File | Save, load toolbars, etc. Your DMS techical guys (NOT
the sales guys - they won't know anything) should be able to tell you what
happens when a document is opened from within the DMS environment. Ask them
what else the DMS tells Word on an "Open" event - if anything.

Note that you may also encounter problems if you try to use an AutoNew macro
in a template under certain DMS configurations. If the template is stored in
the DMS and functionality is provided to create a new document based on this
template from within the DMS, the AutoNew macro probably won't fire either.
This is because many DMSs don't actually create a new document using Word
processes (i.e. execute a Documents.Add event). Instead the template (which
isn't _really_ a template - the DMS stores it as a .doc but calls it a
template) is copied within the DMS document repository, and then this copy is
opened. This usually happens when the DMS is set up to 'pre-profile'
documents and is designed to ensure that no documents can be created which
aren't stored in the DMS. And as discussed above, even using an AutoOpen or
AutoExec macro is no substitute because the DMS may block the code execution.

The best solution is to do all of your document creation processes in the
Word environment and then 'post-profile' the document when it's saved.
However, the decision to pre- or post-profile is usually made some policy
wank who doesn't have any technical nous. Consequently, you end up getting
caught by conflicting requirements: the template _must_ have code in it but
all documents _must_ be created in the DMS environment and the DMS won't let
the code run - and of course the DMS guys won't change their system to
accommodate the requirements, and the policy wank won't change the
requirements...

If you are dealing with sort of situation I suggest that you make a strong
case for going away from pre-profiling. You can write code that forces the
user to save the document as soon as it's created - well, not exactly
"forces" but certainly "strongly encourages". Just make the last line of your
code 'ActiveDocument.Save' and let the DMS take over from there.

You can also be a bit trickier about this. Usually the concern about
creating documents outside of the DMS environment is that the users will save
the document someplace other than the DMS or that they'll print the document
and then close it without saving. The DMS integration can handle the first
scenario by taking away the ability to save the document locally. However,
you can write code to address the second situation.

Create a procedure called 'FilePrint', which will intercept Word's File |
Print command. In this procedure just look at the Saved property of the
document and don't let the document print if it hasn't been saved - and of
course it can't be saved anywhere but into the DMS. You'll also need to
fiddle with the Print button on the Standard toolbar so it executes your
FilePrint macro.

Anyway, good luck in what I suspect will be a protracted battle. Hope you win!
--
Cheers!
Gordon
"I could write really great code - if it wasn't for the bloody users!"

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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