Results 1 to 10 of 10
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening a Mailmerge document (Word97SR2)

    <pre>Sub test4()
    Documents.Open ("d:GreavesPcfFixDB004.dot")
    End Sub
    </pre>


    The document I'm trying to open is a mail-merge document. The Documents.Open produces an annoying user-intervention GUI along the lines of "FixDB004.dot is a mail merge document. Word cannot find its data source CLIENTS.MDB" and two buttons "Find Data Source" and "Options".


    There appears to be no way of testing an unopened document (also known as a FILE!) to check its mail-merge characteristics.


    The mail.merge might be useful, but it is only relevant to an opened document, as in:-
    <pre> ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
    </pre>



    I'd be grateful to hear from anyone who has managed to program around this obstacle. I don't mind if I have to ignore the file, as long as I remain in control. Writing a message to a log file is OK. The program must NOT be allowed to hang all weekend waiting for someone to come along and click with the mouse .....

  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: Opening a Mailmerge document (Word97SR2)

    I can't recall whether this particular dialog has been discussed before in the Lounge, but the problem of a confirmation/error dialog popping up sure sounds familiar. I think you might find a "generalizable" solution doing some searches here... my only other thought is to start a process that watches for the Window title (or other, possibly more unique identifer) of that dialog and, if found, shuts it and exits, and, if not found within an allotted amount of time, shuts itself down. Not sure if this really is feasible, but wouldn't it be great?!

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    Can you wrap the call to Documents.Open betwen an Application.DisplayAlerts = wdAlertsNone and Application.DisplayAlerts = wdAlertsAll?

    StuartR

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    We manage this problem by deliberately not storing a Data Source with Mail Merge documents. We then set those things in code when we want to run a mail merge, and we are careful not to save the merge document with the data source at completion. We actually set the document properties to ReadOnly to prevent users from wreaking havoc too.
    Wendell

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    > been discussed before in the Lounge,

    As is my wont, I did search the VBA forum before posting, because I too had a feeling that it had been discussed, but my search turned up nothing.


    >Not sure if this really is feasible, but wouldn't it be great?!

    Sure. What would be greater would be MS realizing that some of us actually write programs that are supposed to run unattended! I suspect that this pop-up is a legacy from a 3rd-party code takeover/makeover, and that this pop-up didn't get caught and turned into a property!

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    >Application.DisplayAlerts = wdAlertsNone

    Thanks, Stuart, it didn't work, but it's something new that I've learned.

    Your code embracing my code did inhibit the original two-button pop-up, but still left me dangling with an OPEN dialogue box, looking for the recalcitrant database.

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    >deliberately not storing a Data Source with Mail Merge documents

    Excellent policy.


    How about telling it to my client two years ago (grin!).


    I run into these kinds of (legacy) problems periodically. I hate them. The only solution seems to be to institute a pre-processor pass where one tries to (in this case) open each Word document and do nothing to it, just to trap the weirdos, take them out of the loop (or fix them) and then re-run, doing a real process on each remaining file.

    Stuart's code to inhibit the pop-up box did half the trick. I suppose if I could get past the pop-up box (which so far I can't) I could strip the document of its mail-merge characteristics. trouble is, that can be done only on an open document, and I can't open the document without going through the user interface.

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    <How about telling it to my client two years ago (grin!).>

    Actually this part of word has worked that way since Word 6 and Access 2 and has always been a problem. When we went to Office 97, we began using the strategy of not storing a data source in merge documents precisely because of the problem of moved data sources, or data sources that didn't return any records.

    As to your problem, are you running code in Visual Basic, or are you running VBA in Word or Access? If you are running code in VB, you might try switching to Access and use OLE Automation to remove the data source, but you will probably need to do some error trapping to catch errors when you try to do that to a document that is not a mail merge document. As an aside, it's a little odd to have a mail merge document being stored as a template. Is there some reason for it being a template?
    Wendell

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    The original application (the one we want to be in charge) is Word97SR2/VBA, not VB, not Access just Word.

    There are not many such documents (it might be better if there were - we could hire someone to click the mouse every 5 seconds!), so I guess it's just another pain.


    If I were going to do anything to pre-process the documents, I'd probably write a separate VB6 or VBA program to inspect bit such-and-such (or bytes) of all documents on the network prior to running the real job.

    Of course, if client can tells us specifically which DOCs have mailmeerge, we can take them out of the loop beforehand. But they will never know all of them.


    Thanks to you, and to all who responded. My main concern was that I might have missed a Method or Property somewhere. All that I've read in response so far has convinced me that it's a burp in MS, not more of that old-age thingy creeping up on me.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Opening a Mailmerge document (Word97SR2)

    I have found a partial-solution with some of these types of documents by protecting the source code.

    By instituting a password of, well, "password", the templates are locked, and my test for LOCKED templates inhibits my opening them.

    This solution is ONLY acceptable, and at a cost, by being allowed to try opening every template and recording those which are mail-merge, locking those, and then doing the full run.

Posting Permissions

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