Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Mar 2003
    Elkins Park, Pennsylvania, USA
    Thanked 0 Times in 0 Posts

    Creating Master Word Doc from VB (VB 6 / Word XP)

    Hi, all. This one may sound complex, so bear with me:

    I wrote a VB app (more for proof-of-concept than anything else) the purpose of which is to open an existing (blank) document and copy into it all files found in a certain subdirectory. You can see the code in the attached TXT file. The action takes place on a network share, which has an uncomfortable latency issue, over which I'm powerless.

    The code runs fine: it opens the "master" document (it is not a Master document in Word's sense of the term) from the location specified in the dialog box, and then looks for and inserts (using "Insert: File") any files it finds in the same folder. Everything appears to run successfully. But what seems to happen more often than not is that the resulting file is somewhat "corrupted" and crashes Word when I try to open it. And what I find is that there is a "residual" reference to a temp file that no longer exists. (An example of such a reference, which I copied from the References section of one of the files is "COCUME~1BoonieLOCALS~1Temp~WRC1958.tmp") Until i remove this reference, the document will continue to crash Word when opened.

    Also, the resulting document is initially attached to, but ends up being attached to a template that was attached to the files being inserted. (They are all based on the same template.) I have to specifically attach the "combined file" it to in the code to keep this from happening. Interestingly enough, when I do this (i.e. specify NORMAL as the AttachedTemplate), the resulting file rarely, if ever, has that "corruption" issue I mentioned previously.

    Does anyone have any idea what factors might be contributing to this? My suspicion is that the VB code is not waiting for certain things to complete before closing and saving the Word document and closing Word. I made a half-hearted effort to force it to wait (as you can see in the code), but I'm not sure it's working. Could this be because of the way I'm driving Word from VB?

    Please help!
    <font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Creating Master Word Doc from VB (VB 6 / Word XP)

    I don't know why things would go wrong, but instead of using InsertFile, you could try opening each of the "component" documents in turn, copying its contents into the "master" document, then closing it.

Posting Permissions

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