Bad Macro

R

Ron

Using Win2000, Word 2000 English and Chinese.

My supervisor has set up a template file with macros to insert things like
preformatted tables, page headings etc.

All the macros work on his computer, but one macro won't work on any other
computer: the "Alt+A+T". I get a runtime 4198 error when I try to run it.
The code stops here:

Selection.InsertCaption Label:="Figuree", Position:=wdCaptionPositionBelow

He's at his wits end trying to figure out what's wrong and I'm no good at
macros. I've tried attaching the file but it won't go through. I'd
appreciate someone taking a look at this .dot file and helping figure out
this problem.

I hope someone out there can help.

Thanks in advance.
 
J

Jonathan West

Ron said:
Using Win2000, Word 2000 English and Chinese.

My supervisor has set up a template file with macros to insert things like
preformatted tables, page headings etc.

All the macros work on his computer, but one macro won't work on any other
computer: the "Alt+A+T". I get a runtime 4198 error when I try to run it.
The code stops here:

Selection.InsertCaption Label:="Figuree", Position:=wdCaptionPositionBelow

I suspect a typo there. Try changing "Figuree" to "Figure".


--
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
 
R

Ron

There is a predefined style called "Figure". I suspected the same, so I
changed the typo. The macro didn't crash, but it inserted the wrong kind of
caption.

When we first looked at the problem, we knew there wasn't a style named
"Figuree", so we created one, but the macro still wouldn't work.

Thanks for the suggestion.
 
S

Shauna Kelly

Hi Ron

The line of code
Selection.InsertCaption Label:="Figuree", Position:=wdCaptionPositionBelow
is not using a style called "Figuree". It's looking for a caption label
called "Figuree".

Up to and including Word 2003, caption labels are stored in normal.dot. The
line of code will work only on a machine whose normal.dot contains the
caption label "Figuree". For the line of code to run on any other machine,
you would first have to create the relevant label.

You can do that in the user interface with Insert > Reference > Caption >
New Label. If you're later asked if you want to save normal.dot, say yes.

If you want to do that in code, you need to do CaptionLabels.Add
Name:="Figuree" and then set the required properties of your new Caption
Label. Look up CaptionLabels in VBA help for more information.

Bear in mind that adding a new label will dirty the user's normal.dot.
That's generally considered to be a heinous crime; in this case it can't be
avoided.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
R

Robert M. Franz (RMF)

Hi Shauna

Shauna said:
Bear in mind that adding a new label will dirty the user's normal.dot.
That's generally considered to be a heinous crime; in this case it can't be
avoided.

Couldn't you delete it afterwards, in code I mean?

Greetinx
Robert
 
S

Shauna Kelly

Hi Robert

Good point. But Ron wanted to create a template. So I'm assuming that the
purpose is to allow the person who creates a new document based on that
template to create new captions using the label. So if it were deleted, the
user couldn't do that.

The other problem is that if you have a document that uses a Label that's
not one of the CustomLabels collection, then you can't create a
cross-reference to the captions.

Cheers

Shauna

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
R

Robert M. Franz (RMF)

Hi Shauna

Shauna said:
Good point. But Ron wanted to create a template. So I'm assuming that the
purpose is to allow the person who creates a new document based on that
template to create new captions using the label. So if it were deleted, the
user couldn't do that.

The other problem is that if you have a document that uses a Label that's
not one of the CustomLabels collection, then you can't create a
cross-reference to the captions.

Ah, sorry, I was not specific enough: I was thinking about the usual
mantra not to "dirty" normal.dot. Thus, the code to create and delete
the label would have to run in an autoopen/close macro. Hmm, I guess
that's shooting with cannon balls at sparrows (sry if that's a bad
translation .-)).

Greetinx
Robert
 

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