Results 1 to 8 of 8

Thread: [RESOLVED] HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

  1. #1

    Thread Starter
    Lively Member Elvenstone's Avatar
    Join Date
    Feb 2008
    Location
    Rotterdam (Netherlands)
    Posts
    122

    Resolved [RESOLVED] HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    Hi all,

    I'm busting my brain on the error mentioned above and found nothing to help me.

    Here's the issue: I'm using shape objects which I fill with text from my application. In the following example I'm selecting a Shape called "myshape", then filling it with the String "test":

    Code:
    Word.Application.ActiveDocument.Sections(1).Range.ShapeRange("myshape").Select
    Word.Application.Selection.TypeText "test"
    On some users' systems with Word 2003 the error occurs on the first line, but we cannot reproduce it on any of our systems using the same system configuration.

    Oh yes, I found this hotfix: http://support.microsoft.com/kb/910282. It discribes exactly this problem and recommends installing SP3. But the users who are getting this error have Office 2003 SP3 installed.

    I can't imagine I'm the only one dealing with this, so does this look familiar to any of you guys and galls?
    Please be kind enough to RATE a helpful post.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    possibly a better way would be to loop through all the shapes until you get to the one with name = "myshape"
    if it does not find the shape no error will be generated, but supposedly the shape with that name will be found each time, if not it will give you some other problem to sort
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member Elvenstone's Avatar
    Join Date
    Feb 2008
    Location
    Rotterdam (Netherlands)
    Posts
    122

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    It will probably leave my document empty, but thanks for the suggestion. Anyone have any other ideas?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    It will probably leave my document empty,
    how so?
    looping through the shapes will do nothing until it finds one to match the name

    vb Code:
    1. Dim d As Document, sh As Shape
    2. Set d = Documents("document1")
    3. For Each sh In d.Shapes
    4.     If sh.Name = "myshape" Then sh.TextFrame.TextRange.Text = "test"
    5. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Lively Member Elvenstone's Avatar
    Join Date
    Feb 2008
    Location
    Rotterdam (Netherlands)
    Posts
    122

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    'Coz
    vb Code:
    1. ShapeRange("myshape")

    Is functionally the same as looping through the shapes looking for the shape with the given name. In other words: if Word doens't find the shape in this bit of code, it will not find the shape looping through all shapes...
    Please be kind enough to RATE a helpful post.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    that should be correct, but looping through the shapes does not raise an error if the specific shapes is not found, just does nothing, the real question is why the shape is not found and looping through the shapes is much easier to debug, as for example you can print the names of all the shapes to the debug window or log file
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    The assumption is that the shapes is what's causing the error... but unless there's a section to be found... it doesn't matter if the shape exists or not.

    Personally, I'd check to make sure Section(1) is there first... then move down the line to the shape reference, make sure it exists before trying to access any of its properties, and go from there.

    But that's just me.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Lively Member Elvenstone's Avatar
    Join Date
    Feb 2008
    Location
    Rotterdam (Netherlands)
    Posts
    122

    Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"

    Thanks you guys. I've done just that.
    Apparantly one cannot rely on Word when it comes to getting a shape by it's name in all circumstances, so I have been working through my entire project replace the code to first look up the shape's Index.

    No more errors now.
    Please be kind enough to RATE a helpful post.

Posting Permissions

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



Click Here to Expand Forum to Full Width