Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Mail Merge (Word XP - SP2)

    I'm wrestling with the VBA code for merging in Word. The code works well for me, but it doesn't seem to be an efficient way to do things. I'd like to hide this activity from the user, but there doesn't seem to be a good way to do it. The wizard, task pane and merge toolbar all appear at various points and Application.ScreenUpdating = False re-sets each time a document is opened, so that's an issue at several points during this.

    In my existing code, I position the window each time a document opens (in case Word is not maximized) and that reduced the "jumping" effect on the screen. I close the task pane and toolbar at each occasion when they appear, and the reduces the activity as well. But it still seems to be a rather awkward way of merging. I tried setting Visible = False when I open the form document, but that raises an error because the merge fields can't be seen, or else the merge continues, but the end results are wrong.

    For my purpose, I'm opening the form document, merging it with a known data source, copying a part of the output document and pasting that into my original document. I have to close the output document as well as the form document, both of which are made the more complicated by our DMS (iManage) which precludes closing a member of the Documents collection without that document being the active document. So there's lots of jumping and switching. The end result is not smooth. I've worked on it enough so that it's not terrible, but it's not what I'd like it to be.

    Is there perhaps a way of merging via VBA that can avoid the wizard, task pane, toolbar, etc? And is there a way to merge a document that is not visible? It seems odd that Word needs to "see" merge codes... it doesn't need to "see" other things that can occur in a document which has been opened with Visible = False.

    Thanks,
    Richard Barrett

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

    Re: Mail Merge (Word XP - SP2)

    We generally solve the problem by running the merge from another application using Automation - Access nearly always. In that mode you can set it so the only thing the end user sees is the merged output. Of course if your data source is in Word, that may be a challenge, but it has worked well for us and our clients. What is your data source?
    Wendell

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    Thanks.

    My data source is a CSV file. We don't, however, have Access available.

    Richard

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

    Re: Mail Merge (Word XP - SP2)

    You could pull the CSV file into Excel (assuming you don't have text columns over 255 characters), and run the merge automation code from it. I've never tried to use Automation to run one document from another, but I suspect it may not work well.
    Wendell

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    It's a rather simple file.... records with name, mailing address, fax number, phone number, very little more.

    By "Automation" are you referring to using the Word object from Access to merge? I suppose you're starting a hidden instance of Word to do that. I could probably do that from Word itself, couldn't I?

    Does Automation use the same procedure... opening the form file, and merging from that? Or is there a simpler method available through Automation?

    Thanks,

    Richard

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    I've answered my own questions, and I've done this successfully within Word, by creating a new instance of the application and hiding it.

    One question remains... is it possible to start this instance of Word without having the global templates load? That wastes quite a bit of time, and there's no need for them. Do you by any chance know of a way to do this?

    Thanks,
    Richard

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

    Re: Mail Merge (Word XP - SP2)

    Glad you figured it out - I was a bit dubious as to whether you could do that, but it sounds like you made it work. As to skipping the global templates load, you could try using a special template with the main merge document, but I believe the normal template will always load. Hopefully someone else can suggest an alternative.
    Wendell

  8. #8
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    It's not the normal template, but the add-in templates in the Startup folder. We have six or eight of these, some of which have AutoExec macros which establish COM links, etc. It's as long as 10 or 12 seconds on all but the fastest PCs, and that offsets the benefits of this new-found merge technique. So despite the "cleaner" look to the merge process, it takes quite a bit longer.

    I appreciate your help.
    Richard

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

    Re: Mail Merge (Word XP - SP2)

    Well, I did a little digging, and it turns out there is a startup switch you may be able to use - /a says "Start Word and prevent add-ins and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the setting files." according to the Help files. The fact that Normal is not loaded either may be a problem, but you can probably use more switches to get around it. Try searching for startup in the "Asnwer Wizard" and look at the topic [i]Control what happens when you start Word[/],
    Wendell

  10. #10
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    I'm aware of that switch, as well as others which start Word with a particulr document open or by running a macro at startup. The latter prevents AutoExec macros in the global templates from running, and thus would save me the time that's being wasted. But how does that switch come into play when Word is set as a new object using Automation?

    Set appWord = New Word.Application

    That line won't accept any parameters. nor would I expect it to. As there a way that I can start Word using the command line parameter and still have access to the object model in that instance of Word?

    Richard

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

    Re: Mail Merge (Word XP - SP2)

    Well, I haven't found any way to use the command line switches, so perhaps another tactic will work.
    Instead of doing a New Word.Application, try the GetObject approach. It will use the same instance of Word, but your merge doc should still be hidden unless you make it visible. I don't know if that will prevent the global templates from loading, but it appears worth a try.
    Wendell

  12. #12
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    Again, thanks.

    I've tried CreateObject (since I definitely want a new instance of Word), but I get an error with the following code: (I'm writing this in Excel, and for the moment I'm forgetting about the switch... and I'm setting Visible = True because I want to see if anything is happening)

    Dim objWord as Object
    Dim sPath as String
    sPath = Application.Path & "winword.exe"
    Set objWord = CreateObject (sPath)
    objWord.Visible = True

    I get an error on the Set line: Active X cannot create object. (If I use GetObject ("Word.Application") there's no error. Of course there's no switch available to me either.)

    However, if I change the object to a Word document, instead of the application, Word is launched, the document is opened, and I can use Parent.Visible = True to see the instance. But because I've had no opportunity to use the switch, the global templates load. Occasionally these global templates display messages, making them all the more undesirable.

    Any further ideas?

    Thanks
    Richard

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mail Merge (Word XP - SP2)

    You can't call CreateObject with a path and exename; it expects a class name.

    What you should do is launch Word using the Shell instruction, with the /a option to suppress loading of global templates etc.
    Then grab this instance of Word with
    Set objWord = GetObject(, "Word.Application")
    to use the Word object model.

  14. #14
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Mail Merge (Word XP - SP2)

    Thanks very much.

    This will be run from Word (in the real world) as a way of doing a merge in a new instance of the application so the merge process can be hidden. So how will I grab this particular NEW instance of Word as opposed to the current instance? Or will the code assume the new instance?

    Thanks,
    Richard

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mail Merge (Word XP - SP2)

    I hope somebody else can help you here - I still use Word 97. Word 2000 and XP behave differently with respect to starting a new instance, I believe, so I can't tell you what happens if you use GetObject with multiple instances of Word open. Sorry about that.

Page 1 of 2 12 LastLast

Posting Permissions

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