Share via

Create a macro for cross-references

Anonymous
2012-10-18T20:30:30+00:00

Could someone help by creating two macros to accomplish the steps below?

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 the macros, 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 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.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

9 answers

Sort by: Most helpful
  1. Anonymous
    2014-07-20T00:11:55+00:00

    By the way, Microsoft, it looks like the vast majority or users, when inserting a reference, would like to reference to "Only label and number", so pleeease consider making it the default choice??

    Was this answer helpful?

    4 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2015-05-20T02:46:13+00:00

    This works nicely for streamlining the Figure cross-reference process.

    Sub InsertFigureReference()

        With Application.Dialogs(wdDialogInsertCrossReference)

            .ReferenceType = "Figure"

            .ReferenceKind = wdOnlyLabelAndNumber

            .InsertAsHyperlink = True

            .Show

        End With 

    End Sub

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2012-10-19T13:22:34+00:00

    Barb,

    Thanks for your reply.

    The code that I was able to record for the figure cross-reference is below. If we can solve the problem with the figure cross-reference first, then I might be able to modify the code to work with heading text.

    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.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2012-10-19T12:58:48+00:00

    It sure would help to see your code.  ...

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  5. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2014-07-21T00:16:21+00:00

    By the way, Microsoft, it looks like the vast majority or users, when inserting a reference, would like to reference to "Only label and number"

    Really? Can you point to some statistically valid research that backs this up? Or is it just the opinion of the few out of the millions of Word users who post in these forums wanting something different.

    As for code to manipulate the dialogue box, see: http://answers.microsoft.com/en-us/office/forum/officeversion_other-word/changing-the-cross-referencing-default-to-label/18390a17-4edd-46ed-b6f5-851466df6c18?page=2

    Was this answer helpful?

    0 comments No comments