-
Apr 22nd, 2008, 02:57 AM
#1
Thread Starter
Lively Member
[RESOLVED] HELP! Word 2003 error 5941 "The requested member of the collection does not exist"
Please be kind enough to RATE a helpful post.
-
Apr 22nd, 2008, 05:14 AM
#2
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
-
Apr 22nd, 2008, 05:33 AM
#3
Thread Starter
Lively Member
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?
-
Apr 22nd, 2008, 06:27 AM
#4
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:
Dim d As Document, sh As Shape Set d = Documents("document1") For Each sh In d.Shapes If sh.Name = "myshape" Then sh.TextFrame.TextRange.Text = "test" 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
-
Apr 22nd, 2008, 08:19 AM
#5
Thread Starter
Lively Member
Re: HELP! Word 2003 error 5941 "The requested member of the collection does not exist"
'Coz
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.
-
Apr 22nd, 2008, 04:23 PM
#6
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
-
Apr 22nd, 2008, 06:11 PM
#7
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
-
May 2nd, 2008, 03:34 AM
#8
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|