Results 1 to 7 of 7
  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

    using multiple open documents (Word97/2000)

    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

  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: using multiple open documents (Word97/2000)

    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.Tab les(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.

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

    Re: using multiple open documents (Word97/2000)

    > 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.Tab les(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.

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: using multiple open documents (Word97/2000)

    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

  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: using multiple open documents (Word97/2000)

    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!

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: using multiple open documents (Word97/2000)

    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.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  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: using multiple open documents (Word97/2000)

    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 <font color=red>face</font color=red>!

    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.

Posting Permissions

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