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, 7 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
-
two pages side by side land scape
by
marc
5 hours, 45 minutes ago -
Deleting obsolete OneNote notebooks
by
afillat
7 hours, 51 minutes ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
8 hours, 1 minute ago -
Security Essentials or Defender?
by
MalcolmP
8 hours, 4 minutes ago -
April 2025 updates out
by
Susan Bradley
2 hours, 24 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
10 hours, 16 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
10 hours, 19 minutes ago -
Creating an Index in Word 365
by
CWBillow
21 hours, 46 minutes ago -
Coming at Word 365 and Table of Contents
by
CWBillow
21 hours, 51 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
1 day, 2 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
1 day, 6 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
1 day, 8 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
1 day, 6 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
23 hours, 31 minutes ago -
I installed Windows 11 24H2
by
Will Fastie
1 hour, 56 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
1 day, 11 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
1 hour, 26 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
1 day, 19 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
1 day, 4 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
1 day, 4 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
2 days, 12 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
2 days, 21 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
1 day, 23 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
2 days, 5 hours ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
2 days, 16 hours ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
4 days, 8 hours ago -
50 years and counting
by
Susan Bradley
1 day, 6 hours ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 9 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
4 days, 19 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
4 days, 19 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.