Run-time error '5941' & Bill Coan's Word MVP Macrobutton article

M

Marceepoo

I get a Run-time error '5941' (The requested member of the collection does
not exist) error message, when I try to create the macro button that Bill
Coan describes in his article located at:
http://www.word.mvps.org/faqs/macrosvba/AssignMacroToText.htm
Does anyone have any ideas:
1. How to fix the problem?
2. Where (url) I can find an explanation, so that I understand the solution?

Thanks again for the help. You folks are wonderful. Marceepoo
 
M

Marceepoo

No. But after I rec'd your response (below), I did insert the macro into the
Newmacros module of my Normal.dot template, and got the same error message.
I had only saved the macro in the NewMacros module of the document file
(CkBox.doc), from which I was planning to make a template.
1. Thanks for trying. Much appreciated.
2. Any other ideas?
3. If I were to want to keep the macro in a particular template (which, for
discussion purposes, let's assume I want to maintain somewhere other than my
Startup folder), how could I tell the macrobutton where to find the macro?
{MACROBUTTON CkBox N}

Thanks, Marceepoo
 
D

Dawn Crosier

Make your template first - then add your module to the template - then
add your code to the module.

Have you confirmed that the name of the macro is CkBox ? That you
don't have any other macro's called that in your templates either
Normal or the template you are creating?

If you still have problems, please post the code you created for your
module.

--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
 
M

Marceepoo

Dear Dawn: Thanks for following up. I checked to make sure that I have no
other macros bearing the same name...and then I renamed the macro just to be
sure.

Here's what's in the macrobutton:
MACROBUTTON Doofus N

Here's the code:
Sub doofus()
'
' MacroButtonCkBox Macro
' Macro recorded 2005.12.02 by Marc B. Hankin
'
'Cannibalized from Article contributed by Bill Coan Located somewhere
' under http://word.mvps.org/Enable a user to double-click text in a
' document to change its value
'


Select Case Selection.Fields(1).Code.Characters(29)
Case "Y"
Selection.Fields(1).Code.Characters(29) = "N"
Case "N"
Selection.Fields(1).Code.Characters(29) = "?"
Case "?"
Selection.Fields(1).Code.Characters(29) = "Y"
Case Else
End Select

End Sub


Thanks again,
marceepoo
 
J

Jonathan West

It all becomes much clearer once you provide the code!

The problem is that your macro name is shorter than the one in Bill's
article, which means that your MACROBUTTON field doesn't have 29 characters
in it. The error is telling you that there isn't a 29th item in the
Characters collection of the field.

You have to change the 29 to the appropriate number for the position of the
N in your field.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top