Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    DocumentChange Event (Word 2000)

    It is my understanding that the DocumentChange event fires when "a new document is created, when an existing document is opened, or when another document is made the active document."

    I am using WindowsSelectionChange to check to see if my end-users are trying to open the header. If they are I'm closing the header and instead showing them a form from which they can modify header info with. When the form loads I'm pulling in document properties such as keywords, title etc.. When they click ok I'm updating the doc properties, and all the headers and footers. My DocumentChange event is firing 76 times after it leaves the WindowsSelectionChange event! I only have one document open too. Can someone tell me why this is happening?

  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: DocumentChange Event (Word 2000)

    Hi Kyle,

    I had the same problem updating from Office 97 to Office XP/2003. If a user tried to create a new document from a template with no other documents opened, the DocumentChange event handler went into an endless loop. If there was another document opened, the DocumentChange event fired from 20 up to 150 times, causing inacceptable delay. I still don't know why this occurs. But I aborted the use of DocumentChange altogether and use the NewDocument and DocumentOpen events instead. And these work like a charm.

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: DocumentChange Event (Word 2000)

    Thanks. I think I figured out the problem. Because my update headers routine is using the range property it is somehow triggering the DocumentChangeEvent. Here is my code:

    For Each oSection In oRange.Sections
    With oSection
    .Headers(wdHeaderFooterPrimary).Range.Fields.Updat e
    .Headers(wdHeaderFooterFirstPage).Range.Fields.Upd ate
    .Footers(wdHeaderFooterPrimary).Range.Fields.Updat e
    .Footers(wdHeaderFooterFirstPage).Range.Fields.Upd ate
    End With
    Next oSection

    Because my document has 19 sections and I'm updating 4 headers/footers my DocumentChangeEvent is triggering 76 times. I don't know how else to automatically update the fields in my headers and footers. Any suggestions?

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: DocumentChange Event (Word 2000)

    In theory, Print Preview will updates the header and footer fields. But I don't know whether simply previewing the first page would cover all sections. Also, it could be visually jarring. Never mind. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: DocumentChange Event (Word 2000)

    Thanks. I did found some code that updates the fields by using StoryRanges. This only triggers 4 hits of the DocumentChangeEvent. This is much better than the previous 76 hits.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: DocumentChange Event (Word 2000)

    It's good to hear that StoryRanges works for field updating. In some situations, it only operates on the headers and footers of the first section.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •