Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Possibility to identify a mailmerge docume (Word2k)

    I'm having VBA-code, that should only run in "normal" documents, but not in documents created by mailmerging. Is there any way to identify such a document? (The newly created document when a mailmerge with a new document as destination is executed.)

    thanks in advance
    hedgehog

  2. #2
    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: Possibility to identify a mailmerge docume (Word2k)

    <P ID="edit" class=small>(Edited by jscher2000 on 09-Sep-03 10:32. On second thought...)</P>Good one! What I find helpful in tracking down these properties is to pop up the object browser (F2) and search for a term I think will help, in this case merge since I thought perhaps the existence of a data document might flag a document as a merge document. Scrolling down the list, I saw MailMergeDataSource. Highlighted that and hit F1. I clicked up the object tree in help to the MailMerge object and in the first paragrah, it mentions a State property. The State property help looks like the answer:

    <UL>Returns the current state of a mail merge operation. Read-only WdMailMergeState.

    WdMailMergeState can be one of these WdMailMergeState constants.
    wdDataSource
    wdMainAndDataSource
    wdMainAndHeader
    wdMainAndSourceAndHeader
    wdMainDocumentOnly
    wdNormalDocument[/list]In other words <img src=/S/smile.gif border=0 alt=smile width=15 height=15> , this could be your first attempt:

    if not activedocument.MailMerge.State =wdNormalDocument then exit sub

    Added: That should work in the merge document itself. But if you don't want it to work in the wdNormalDocument that (presumably) results from the merge, I think you'll have to dig around a bit more. Perhaps you will need to insert some kind of marker in the document so you know one when you see it.

  3. #3
    Star Lounger
    Join Date
    Sep 2001
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Possibility to identify a mailmerge docume (Word2k)

    Hi Jefferson

    Thanks for the reply. And that's exactly what I did before posting (Sorry my description was probably to short.). I looked for available properties in the object browser - but unfortunately MailMerge.State will only return wdNormalDocument for the document type. Since there are other non-mailmerge documents which were generated by the same template, this doesn't work.
    In Word XP I might catch one of the mailmerge events and mark the newly created document. But in Word 2k no mailmerge events exist :-/

    Right now, I've run out of ideas - but it keeps bothering me. If you have another idea, I would really appreciate it.

    Thanks,
    hedgehog

  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: Possibility to identify a mailmerge docume (Word2k)

    Going forward, what happens if you create a custom property in the main document. Does it carry over to the merge results document? Obviously that can't work "retroactively," but...

  5. #5
    Star Lounger
    Join Date
    Sep 2001
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Possibility to identify a mailmerge docume (Word2k)

    Unfortunately it seems to copy all built-in and custom properties as well. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    I did some further testing, document variables are copied as well, but I think I found one difference now: Bookmarks are not copied (except bookmarks placed in a header or footer.) Since the original template already contains bookmarks, I seem to have found a solution for the problem. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Thanks for your help.

Posting Permissions

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