DocumentChange event not working the same from Word97 to Word 2002

S

Susan K. Brown

I have programmed a template which uses the DocumentChange event to reset
some custom toolbars I use. This template is programmed in Word97 and is
now being used on Word 2002 on an XP machine. The DocumentChange event
seems to be triggered at different times other than when a new document is
created, a different document is opened or you switch to a different
document in Word 2002. I've tested it in both environments and it is not
being triggered in Word 97 but is in Word 2002.

One thing that I did do on the Word 2002 machine was to put breakpoints in
and step through the code. When I put the breakpoint in the DocumentChange
event, it went through that, but when I put the breakpoint in before the
DocumentChange event (I put it in the AutoNew code), it never went through
the DocumentChange event.

Please help. Do these events work differently between Word97 and Word 2002?

Thanks,

Susan Brown
 
S

Susan K. Brown

Here is some more detail on this problem:

In my one template, I attach another template which contains autotext
entries using AddIns.Add. I then use the following line to insert an
autotext entry into my document (This one happens to be in a footer).

Set footRange =
ActiveDocument.Sections(seccnt).Footers(wdHeaderFooterPrimary).Range
Templates(glbATTemplateName).AutoTextEntries("Chubb Disclaimer").Insert
Where:=footRange, RichText:=True

I looked at the Call Stack when I broke in the App_DocumentChange routine
and it was on the Templates statement when it triggered the
App_DocumentChange routine.

In Word 97, the Templates statement does not trigger the App_DocumentChange
routine.

Another very strange thing about this is that in the Word 2002, when I put a
breakpoint in the App_DocumentChange routine it does execute that routine.
When I put a breakpoint in the code that actually creates my document (the
routine that calls the routine where the above statements reside), the
App_DocumentChange routine is not triggered even though it does execute the
above statements.

Please, any help would be greatly appreciated.

Thanks,

Susan
 
P

Peter Hewett

Hi Susan K. Brown

As far as I'm aware they are identical. I don't have Word 97 installed but I
checked my documentation and it's the same as XP. I can only trigger the
"DocumentChange" event when it's supposed to occur. I tried inserting AutoText
from a variety of sources but it made no difference.

All I can suggest is a test regime. In the ThisDocument module I added the
following code.

Private WithEvents appWord As Word.Application

Public Sub HookEmUp()
Set appWord = Application
End Sub

Private Sub appWord_DocumentChange()
MsgBox "DocumentChange"
End Sub

I instantiated the event handler manually by running the HookEmUp procedure. I
then used the IDEs Immediate window to executed various lines to code to trigger
the "DocumentChange" event and insert AutoText. Everything worked exactly as
expected.

All I can suggest is that you use the above approach so that you can runs lines
of code from the Immediate window to see exactly what causes the problem and
when.

Good luck.

HTH + Cheers - Peter
 
S

Susan K. Brown

Peter,

Thanks for the help. What I discovered was that when the globally defined
template (AddIn) was accessed to use the autotext entries, it is executing
the DocumentChange event in 2002 but not in 97 (This template is developed
on 97 but runs on 2002). For now, I've got a workaround. I'm putting in a
flag (glbExecDocChange = false) whenever I access that template and
resetting it right after I access the template (glbExecDocChange = true).
Then at the beginning of DocumentChange event, I check the flag and exit sub
if glbExecDocChange = false.

Thanks again,

Susan
 
J

Jezebel

I'm not sure this is right about 97 working the same as XP. I can't test it
either, but my recollection is that the Event model was introduced after
Word 97 -- which would certainly explain the OP's problem.
 
P

Peter Hewett

Hi Jezebel

The Document change (and Quit) events are documented in my copy of Office 97
Visual Basic Programmers Guide.

Using XP I could not reproduce Susan's problem and I tried AutoText from a
standard template, Normal.dot and an Add-In. I did not specifically try a
referenced template as these seem to be treated the same as Add-Ins.

Cheers - Peter


I'm not sure this is right about 97 working the same as XP. I can't test it
either, but my recollection is that the Event model was introduced after
Word 97 -- which would certainly explain the OP's problem.

HTH + Cheers - 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