DocumentBeforeSave

A

Asimov

Hi!

I try to capture the DocumentBeforeSave event in a word macro, but my code
is never reached. What's the way to capture a Word event?

Thanks,

Asimov.
 
K

K Mogridge

I've just tried doing this but the only events available
are DocumentChange and Quit (I want to use BeforeClose).
I'm working on Word 97 - are the BeforeClose and
BeforeSave events only available in Word 2000? And if
they can't be used with Word 97, please does anyone know
how I can intercept and if necessary cancel the closure of
a Word 97 document?

Thanks.

-----Original Message-----
It's tricky. You can trap events only in a class module. So --

1. Add a class module to your macro project.
2. In the module-level declarations, add

Dim withevents mWordApp as Word.Application

3. Click the left-hand listbox at the top of the code window. You'll find
mWordApp now listed there. If you select it, the right- hand listbox will
contain the events for that object, including DocumentBeforeSave. Select
that and add your before save code.

4. In the Class module's Initialize event, add: Set mWordApp = New
Word.Application

5. In the main module of your project you need to instantiate your class
module. Any number of ways depending on what you need, but simple is to add
a module-level reference to your class module:

Dim mMyClass as new [ClassName] (whatever name you gave to the class module)

and somewhere you need to run this line:

Set mMyClass = new [ClassName] (You could put this code in an Auto macro,
or in a macro that you call explicitly when you want to start up your
system.


You also need to destroy all objects when no longer needed, using Set ... =
nothing




Asimov said:
Hi!

I try to capture the DocumentBeforeSave event in a word macro, but my code
is never reached. What's the way to capture a Word event?

Thanks,

Asimov.


.
 

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