Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recorded macro won't run in Word 2010

Status
Not open for further replies.

Bruce18W

Technical User
May 9, 2011
27
US
Hi,

I recorded this macro in Word 2010 (intending to later modify it). Note, when I recorded the macro, Word inserted a figure reference, which is what I wanted it to do.

Sub Macro3()
Selection.InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:="1", InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
End Sub

When I tried to run the macro, I received the error:

Run-time error '4198':
Command failed

I think I disabled most of the security settings for running macros (especially my own!), but still cannot get this little snippet to run. Any ideas?

Thanks, Bruce
 
The macro works fine when I run it, provided there is a 'Figure 1' Caption to insert the cross-reference to. Without the 'Figure 1' Caption, you will indeed get the Run-time error '4198'.

Do note that, as coded, your macro can only ever insert a cross-reference to the 'Figure 1' Caption.

Cheers
Paul Edstein
[MS MVP - Word]
 
Paul,
Thanks for the tip. There is indeed a Figure 1 caption in the document. I recorded the macro as I was creating the cross reference to Figure 1. When I then tried to run the macro, I received the error. Do you have any other ideas?

Bruce
 
As I said, in my testing the macro runs fine - provided there is a Figure 1 caption in the document.

Cheers
Paul Edstein
[MS MVP - Word]
 
You might have to tweak this a little, but I think it does something close to what you want:

Code:
Sub Macro1()

    With Selection
        .InsertCaption Label:="Figure", TitleAutoText:="", Title:="", _
            Position:=wdCaptionPositionBelow, ExcludeLabel:=0
        .InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
            wdOnlyLabelAndNumber, ReferenceItem:="1", InsertAsHyperlink:=True, _
            IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
    End With
End Sub

 
Thanks for your post.

In my original post, I stated that this is a recorded macro, that is, I used Word to record this macro while I inserted a reference to a figure. When I recorded this macro, Word did indeed insert a reference to a figure. I do not think the code is the problem.

Rather, Word has some settings that are preventing this code from running within VBA. Also, now I cannot even record a macro in Word. I think it's time to reinstall Word, but before I do that, does anyone know which security settings (or other settings) might be preventing this code from running or preventing me from recording a macro.

Thanks, Bruce
 
Hi Bruce,

Word's macro security settings (configurable via Developer|Macro Security) can prevent macros from running, but would not cause Run-time error '4198'. The normal macro security setting for the safe running of macros is "Disable all macro with notification".

As for reinstalling Word, you might find that just closing & re-starting Windows fixes things; if not a repair is just as likely to fix anything that a reinstall might. You can repair the Office installation via Programs & Features > Microsoft Office > Change in the Windows Control Panel.

Cheers
Paul Edstein
[MS MVP - Word]
 
Paul,
Thanks for the suggestions. I rebooted computer (error still appeared) and repaired Office (error still appeared). I have a similar function that inserts heading references, and that works fine. I once again created a macro by recording the keystrokes that insert a figure cross reference. When I tried running the macro, I again received the error, Run-time error '4198': Command failed .

Any more ideas?

Thanks, Bruce

Sub Macro7()
'
' Macro7 Macro
'
'
Selection.InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:="1", InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
End Sub
 
Before reinstall, you might try closing Word, renaming your normal.dot file to something else, start Word again and see if you still have the problem. Word will create a new clean normal.dot file. If your macro is in the normal.dot file, you will have to put it in the new normal file before you can test.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top