One of my clients has huge documents – 100s of headings – when they go to insert a cross reference they are grumpy about scrolling through all the headings. Any simple way of getting to (say) 10.3.2 in the insert cross reference box?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Shortcut to insert cross reference (Word XP)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Shortcut to insert cross reference (Word XP)
- This topic has 12 replies, 6 voices, and was last updated 19 years, 9 months ago.
AuthorTopicWSJudithKiwi
AskWoody LoungerMay 18, 2005 at 10:18 pm #419720Viewing 1 reply threadAuthorReplies-
WSAndrew77
AskWoody LoungerMay 19, 2005 at 2:03 am #948602The Cross-Reference dialog is very buggy when you try to work with it from VBA (I’ve talked about a bit in other posts recently, actually). I’d personally suggest staying away from anything more complicated than using the .Show method. I got so fed up with it with in my own templates that I built an entirely new dialog, just to have something easier to work with. But I doubt you’re interested in taking things that far.
Given the initial condition that your client already knows what they want to reference (10.3.2 for example), would it be acceptable for them to type that in literally, then select it and run a macro? (from a keybinding or the shortcut menu). If so, the following will try to match the selected text to a heading number, and if found, replace the selection with a cross reference to that heading. Your example didn’t include any trailing period on the number; if your actual document does have a trailing period, you’ll need to modify the code slightly.
In the interest of simplicity, this code assumes the selected text is just the number — no leading or trailing spaces. It’s fairly easy to collapse the selection first, just ask if you’d like a pointer.
Sub ReplaceSelectionWithXRef() Dim vHeadings As Variant Dim v As Variant Dim k As Integer Dim sel As Selection Set sel = Selection vHeadings = sel.Document.GetCrossReferenceItems(wdRefTypeHeading) k = 1 For Each v In vHeadings If Split(Trim(v))(0) = sel.Text Then sel.InsertCrossReference _ referencetype:=wdRefTypeHeading, _ referencekind:=wdNumberNoContext, _ referenceitem:=k Exit Sub End If k = k + 1 Next v MsgBox "Couldn't match: " & Selection.Text End Sub
Alert readers will notice this is just an adaptation of Hack #43
.
-
PeterG
AskWoody LoungerAugust 22, 2005 at 1:27 pm #967935What I need to do is create a table in a document that in column 1 lists all the heading numbers and in column 2 shows the matching heading text.
Ideally I would like to automatically create those columns which of course mirror the Contents. However to get the show on the road I can type in the numbers for column 1 and then use the macro that Andrew Savikas has hacked (his words).
Does anyone have any ideas please for
1] Automatically populating the table (for those curious it will have two further columns to which various document refererences will be manually entered)
2] Inserting the matching heading text.
Thanks.
-
WSHansV
AskWoody LoungerAugust 22, 2005 at 9:42 pm #968091Try this. The insertion point should be where you want the table.
Sub ListHeadingsInTable()
Dim vHeadings As Variant
Dim v As Variant
Dim i As Integer
Dim sel As SelectionActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=2
vHeadings = ActiveDocument.GetCrossReferenceItems(ReferenceType:=wdRefTypeHeading)
For i = 1 To UBound(vHeadings)
Selection.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdNumberFullContext, ReferenceItem:=i
Selection.MoveRight Unit:=wdCell
Selection.InsertCrossReference ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdContentText, ReferenceItem:=i
If i < UBound(vHeadings) Then
Selection.MoveRight Unit:=wdCell
End If
Next i
End Sub -
PeterG
AskWoody LoungerAugust 23, 2005 at 6:09 am #968139Hans that is just so cool your fingers must have frozen.
Two things happen when running the macro. After every so many headings (about 16) a warning comes up “Word has insufficient memory etc” but the Yes option continues the macro so it is not a real problem.
After inserting the last item instead of closing the standard Run Time error 4198 Command failed message appears. Again it is not a real problem so I only come back in case it is one of those easy things to fix.
Bottom line though is it does the job so thank you, once again.
-
WSHansV
AskWoody LoungerAugust 23, 2005 at 6:17 am #968142I haven’t tested the code on long documents, only on two short documents created for this purpose only. It ran without problems there. Since Word stores all modifications to a document in the undo buffer, even when executing a macro, it is quite possible that Word has to flush the undo buffer from time to time while running the macro on a long document with lots of heading paragraphs. I don’t know where the 4198 error comes from, though.
-
PeterG
AskWoody Lounger -
PeterG
AskWoody LoungerAugust 23, 2005 at 9:26 am #968156Hans
I was singing your praises as your macro is saving me a lot of time. One of our developers who wouldn’t know the Word commands heard me and took a look and saw what causes the runtime error.
He inserted a little bit of code at the end after the first line below.
Selection.MoveRight Unit:=wdCell
Else
Exit Sub
End If
Next i
End SubHope this helps anyone else who may find Hans’ macro useful.
-
WSHansV
AskWoody Lounger
-
-
-
-
WSgeoric1
AskWoody Lounger -
WSAndrew77
AskWoody Lounger -
WSgeoric1
AskWoody Lounger
-
-
-
-
WSjudithmc
AskWoody LoungerMay 19, 2005 at 3:42 am #948605Judith,
I also get frustrated when using the x-ref dialogue box. My cross refernces usually take the form of ‘Refer to “10.2.6 How to do this” on page 59’ To put this in needs 3 uses of the dialogue box – heading number, heading text and page number.
This is what I do to save a little time:
1) Add a button on a toolbar so I don’t have to navigate through all the menus to get to insert x-ref.
2) With the cursor between the inverted commas, I insert the x-ref to the heading number by scrolling down. Without closing the dialogue box, I insert the heading text and then the page number. (If you close the dialogue box, you have to scroll down and find to the heading again!)
That gives me ‘Refer to “10.2.6How to do this59″‘, to which I then space out as necessary.By the way Judith, isn’t NZ “DownUnder and EAST a bit”?
Regards,
Judith
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
5 hours, 14 minutes ago -
Flash Drive Eject Error for Still In Use
by
J9438
6 hours, 47 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
1 day ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
1 day ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
3 hours, 46 minutes ago -
Migrate off MS365 to Apple Products
by
dmt_3904
4 hours, 34 minutes ago -
Login screen icon
by
CWBillow
7 hours, 13 minutes ago -
AI coming to everything
by
Susan Bradley
2 hours, 33 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
1 day, 15 hours ago -
No Screen TurnOff???
by
CWBillow
1 day, 16 hours ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
1 day, 16 hours ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
2 days, 4 hours ago -
How well does your browser block trackers?
by
n0ads
1 day, 14 hours ago -
You can’t handle me
by
Susan Bradley
14 hours, 33 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
1 day, 7 hours ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
2 days, 15 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
1 day, 19 hours ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
2 days, 16 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
2 days, 16 hours ago -
Lumma malware takedown
by
EyesOnWindows
2 days, 4 hours ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
3 days ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
3 days ago -
Meet Gemini in Chrome
by
Alex5723
3 days, 4 hours ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
3 days, 5 hours ago -
Trump signs Take It Down Act
by
Alex5723
3 days, 13 hours ago -
Do you have a maintenance window?
by
Susan Bradley
1 day, 17 hours ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
2 days, 15 hours ago -
Cox Communications and Charter Communications to merge
by
not so anon
3 days, 16 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
1 hour, 20 minutes ago -
hibernate activation
by
e_belmont
4 days, 1 hour ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.