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?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
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,
JudithViewing 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
-
X Suspends Encrypted DMs
by
Alex5723
1 hour, 13 minutes ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
1 hour, 31 minutes ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
2 hours, 8 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
2 hours, 45 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
2 hours, 9 minutes ago -
Enabling Secureboot
by
ITguy
5 hours, 55 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
10 hours, 40 minutes ago -
No more rounded corners??
by
CWBillow
6 hours, 28 minutes ago -
Android 15 and IPV6
by
Win7and10
29 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
23 hours, 1 minute ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
1 day, 1 hour ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
20 hours, 17 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
1 day, 9 hours ago -
May preview updates
by
Susan Bradley
20 hours, 25 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
12 hours ago -
Just got this pop-up page while browsing
by
Alex5723
1 day, 1 hour ago -
KB5058379 / KB 5061768 Failures
by
crown
22 hours, 18 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
28 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
11 hours, 36 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days, 12 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
11 hours, 11 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days, 2 hours ago -
Another test post
by
gtd12345
3 days, 2 hours ago -
Connect to someone else computer
by
wadeer
2 days, 20 hours ago -
Limit on User names?
by
CWBillow
3 days ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 13 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 21 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 20 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
2 days, 16 hours 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.