• using multiple open documents (Word97/2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » using multiple open documents (Word97/2000)

    Author
    Topic
    #398112

    How do you open one or more documents in Word2000, and then make use of them?

    My application runs well in Word97SR2, but fails on a colleagues Word200 system. Excerpts of code are in the attached Text file.

    I suspect the problem is caused by Word2000 treating each opened document as a separate application, whereas Word97 treats each opened document as a window within the same appliaction.

    My application template GLUER opens up a document called GRABR.DOC, and the colleague sees this.

    Gluer then goes to prime a list box with data from the GRABR.DOC, which I had identified as “doc” in a global variable. On my system (Word97) “doc” is accessed and the list box is primed. On my colleagues system (Word2000), the 5941 error results “the requested member of the collection does not exist”, or such like.

    The MSKB articles give workarounds that seem to consist of trapping the error, but no solution that will let me actually use the document which I have successfully opened!
    See for example http://support.microsoft.com/default.aspx?…kb;EN-US;170892%5B/url%5D

    Viewing 3 reply threads
    Author
    Replies
    • #758921

      Using the Documents.Open method does not create a new instance of the Word application, it simply adds a document that contains a separate SDI window. Are you using that method or are you Shell-ing or…?

      It sounds elementary, but if the error is in this line —

      Set rngTBL = doc.Bookmarks(strcInterestingWordsTable).Range.Tables(1).Range

      — it is impossible to draw any conclusions about what might or might not be missing. I would insert a Stop statement on the line before, open my your Locals window, and drill down through the objects/properties to see if in fact they do exist.

      • #759163

        > Using the Documents.Open method does not create a new instance of the Word application, it simply adds a document that contains a separate SDI window. Are you using that method or are you Shell-ing or…?
        I’m not SHELLing, I’m merely performing a “Documents.Open ”

        > Set rngTBL = doc.Bookmarks(strcInterestingWordsTable).Range.Tables(1).Range
        > it is impossible to draw any conclusions about what might or might not be missing. I would insert a Stop statement on the line before, open my your Locals window, and drill down through the objects/properties to see if in fact they do exist.

        The code works flawlessly (!) on my Win98/Word97SR2; it bogs down at that line on my client’s Win200/Word200 system.
        The bookmarks are present (I sent the two reqired data documents along with the appliaction template to the client), and that led me to believe that the “doc” just somehow wasn’t visible to the client’s system.
        I can’t debug, because it happens at the client site, and he’s not supposed to be debugging VBA.
        I know that the documents are open, because two tests (attached TwoTests.txt) run well.
        I’m not sure now why I assume that it is a problem accessing the documents as “Document” objects. In the back of my mind is the thought that if I passa a document’s fulkl name, and use “Documents(strFullname)” rather than by passing a Document object, I might have a better chance of loacting the opened documents.
        Mainly I supposed that there was some cute trick about the SDI windows (thanks for that terminology!) that I’d not met.

        • #759181

          I don’t know why the described problem occurrs, unless Table(1) is not within the specified bookmaark range.
          In the past I had some trouble with bookmarks (not) containing text too and I found out that another approach worked better.
          Leave at least 1 blank line before and after the table. Insert a bookmark “First” in the blank line before the table and a bookmark “Last” in the blank line after the table. Now try this code:

          Sub Test
          Dim rngBlock As Range
          With ActiveDocument
          Set rngBlock = .Range(.Bookmarks(“First”).Range.End + 1, _
          .Bookmarks(“Last”).Range.Start)
          rngBlock.Select
          End With
          End Sub

          Hope this helpes.
          Jan

          • #759185

            Jan, thanks for the tip, but the bookmarks are in place.

            The application template and two bookmarked documents work fine here. I PKZip them to client, who unzips them and tries to run them with no success.

            I know that the bookmarks are there (because client is savvy enough to choose Edit, Goto, Bookmarks, and can see my three tables in the database document selected as they should be).

            To my mind it is as if the Document object isn’t being found, or isn’t making all its properties available.

            I’ll devise some more tests today, but we know that the bookmarks are in place. We haven’t gotten far enough to corrupt them, yet!

          • #759186

            Jan, thanks for the tip, but the bookmarks are in place.

            The application template and two bookmarked documents work fine here. I PKZip them to client, who unzips them and tries to run them with no success.

            I know that the bookmarks are there (because client is savvy enough to choose Edit, Goto, Bookmarks, and can see my three tables in the database document selected as they should be).

            To my mind it is as if the Document object isn’t being found, or isn’t making all its properties available.

            I’ll devise some more tests today, but we know that the bookmarks are in place. We haven’t gotten far enough to corrupt them, yet!

        • #759182

          I don’t know why the described problem occurrs, unless Table(1) is not within the specified bookmaark range.
          In the past I had some trouble with bookmarks (not) containing text too and I found out that another approach worked better.
          Leave at least 1 blank line before and after the table. Insert a bookmark “First” in the blank line before the table and a bookmark “Last” in the blank line after the table. Now try this code:

          Sub Test
          Dim rngBlock As Range
          With ActiveDocument
          Set rngBlock = .Range(.Bookmarks(“First”).Range.End + 1, _
          .Bookmarks(“Last”).Range.Start)
          rngBlock.Select
          End With
          End Sub

          Hope this helpes.
          Jan

      • #759164

        > Using the Documents.Open method does not create a new instance of the Word application, it simply adds a document that contains a separate SDI window. Are you using that method or are you Shell-ing or…?
        I’m not SHELLing, I’m merely performing a “Documents.Open ”

        > Set rngTBL = doc.Bookmarks(strcInterestingWordsTable).Range.Tables(1).Range
        > it is impossible to draw any conclusions about what might or might not be missing. I would insert a Stop statement on the line before, open my your Locals window, and drill down through the objects/properties to see if in fact they do exist.

        The code works flawlessly (!) on my Win98/Word97SR2; it bogs down at that line on my client’s Win200/Word200 system.
        The bookmarks are present (I sent the two reqired data documents along with the appliaction template to the client), and that led me to believe that the “doc” just somehow wasn’t visible to the client’s system.
        I can’t debug, because it happens at the client site, and he’s not supposed to be debugging VBA.
        I know that the documents are open, because two tests (attached TwoTests.txt) run well.
        I’m not sure now why I assume that it is a problem accessing the documents as “Document” objects. In the back of my mind is the thought that if I passa a document’s fulkl name, and use “Documents(strFullname)” rather than by passing a Document object, I might have a better chance of loacting the opened documents.
        Mainly I supposed that there was some cute trick about the SDI windows (thanks for that terminology!) that I’d not met.

    • #758922

      Using the Documents.Open method does not create a new instance of the Word application, it simply adds a document that contains a separate SDI window. Are you using that method or are you Shell-ing or…?

      It sounds elementary, but if the error is in this line —

      Set rngTBL = doc.Bookmarks(strcInterestingWordsTable).Range.Tables(1).Range

      — it is impossible to draw any conclusions about what might or might not be missing. I would insert a Stop statement on the line before, open my your Locals window, and drill down through the objects/properties to see if in fact they do exist.

    • #759330

      Chris

      Are you defining the documents so that you can work with them? Something like this lets you control which document is which.
      Dim doc1 As Word.Document
      Dim doc2 As Word.Document
      Set doc1 = ActiveDocument
      Set doc2 = Documents.Add
      Debug.Print doc1.Name
      Debug.Print doc2.Name
      doc1.Activate
      doc2.Activate

      Once each document is defined then you can tell the code which document you want to work on.

      • #760676

        Apologies for the tardiness of replies. I am now the proud parent of the world’s most BEAUTIFUL ginger cat, one year old, excellent behaviour. More details in the Cat-Lover’s Forum.

        > Are you defining the documents so that you can work with them? Something like this lets you control which document is which.

        Boy! Is my face!

        After much to-and-fro, we discovered that the original replies on Woody’s Lounge were SPOT ON!

        Between us client and I screwed up the storage of the pre-loaded database document.

        Smarty that I am, my code catered for a startup scenario, when discovering no database document, by creating a virgin database document. And that’s what happened. Client WAS looking at a document that HAD NO bookmarks in the collection.

        However, I wasn’t smart enough to code a cautionary pop-up box along the lines of “I discovered no database document so am creating an empty one”, which would have alerted us to the accuracy of Lounger’s diagnoses.

      • #760677

        Apologies for the tardiness of replies. I am now the proud parent of the world’s most BEAUTIFUL ginger cat, one year old, excellent behaviour. More details in the Cat-Lover’s Forum.

        > Are you defining the documents so that you can work with them? Something like this lets you control which document is which.

        Boy! Is my face!

        After much to-and-fro, we discovered that the original replies on Woody’s Lounge were SPOT ON!

        Between us client and I screwed up the storage of the pre-loaded database document.

        Smarty that I am, my code catered for a startup scenario, when discovering no database document, by creating a virgin database document. And that’s what happened. Client WAS looking at a document that HAD NO bookmarks in the collection.

        However, I wasn’t smart enough to code a cautionary pop-up box along the lines of “I discovered no database document so am creating an empty one”, which would have alerted us to the accuracy of Lounger’s diagnoses.

    • #759331

      Chris

      Are you defining the documents so that you can work with them? Something like this lets you control which document is which.
      Dim doc1 As Word.Document
      Dim doc2 As Word.Document
      Set doc1 = ActiveDocument
      Set doc2 = Documents.Add
      Debug.Print doc1.Name
      Debug.Print doc2.Name
      doc1.Activate
      doc2.Activate

      Once each document is defined then you can tell the code which document you want to work on.

    Viewing 3 reply threads
    Reply To: using multiple open documents (Word97/2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: