We help IT Professionals succeed at work.
Get Started

Word Macro for Insert Cross-Reference

JasonLattin
JasonLattin asked
on
3,986 Views
Last Modified: 2012-10-24
I need some help with macros that I can use in Word 2010.

Could you help me create two macros to accomplish the steps below? If you can help with one, I may be able to tweak it to create the second version.

I plan to associate the macros with buttons and add the buttons to the Quick Access Toolbar (QAT). This will make it easier to insert the two types of cross-references.

I have tried recording a macro, but the steps aren’t recorded unless I complete the entire process, that is, select the item to be inserted as the cross-reference. I want the macro to stop before actually inserting the cross-reference, which will make it possible for me to manually select the reference to be inserted.

I also tried recording the macro to the point of actually inserting a cross-reference and then removing the unwanted steps. The removal of the steps created an error in the macro that I can’t resolve.

If I use the macros, I can limit the number of selections I have to make when I insert cross references.

Steps for Figure Cross-Reference


Insert tab. Click Cross-reference.
Reference type (select) Figure.
Insert reference to (select) Only label and number
Insert as hyperlink selected (yes)

Stop

At this point, I will manually select the appropriate figure number (heading for the next version of the macro) and click Insert.


Steps for Heading Cross-Reference


Insert Cross-reference.
Reference type (select) Heading
Insert reference to (select) Heading text
Insert as hyperlink selected (yes)

Stop


The macros should run regardless of the values selected as the reference type and the insert reference. That is, because the selected values are persisted each time the Cross-Reference dialog box is closed, running the macro should not fail when the persisted state is the same as the stated defined by the macro.



The code that I was able to record for the figure cross-reference is below.


Sub CrossRefFigure()
'
' CrossRefFigure Macro
' Opens Cross Reference dialog box. Selects the reference type FIGURE,
' insert reference to only label and number, insert as hyperlink options.
' Macro stops here for user input of the figure number to be used.
'
    Selection.InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
        wdOnlyLabelAndNumber, ReferenceItem:="1", InsertAsHyperlink:=True, _
        IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "

End Sub

I modified the code and removed the ReferenceItem:=”1” reference. The idea is to have the macro stop at this point so that I can select the figure number to be inserted. However, I got an error.

THANK YOU FOR YOUR ASSISTANCE
Comment
Watch Question
Retired
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE