Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2016, 08:07 AM
cyclops755 cyclops755 is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 7 64bit Define custom Cross-reference output format to include "static" text and pg numbers Office 2010 64bit
Novice
Define custom Cross-reference output format to include "static" text and pg numbers
 
Join Date: Feb 2016
Posts: 1
cyclops755 is on a distinguished road
Default Define custom Cross-reference output format to include "static" text and pg numbers


Hey there all, I'm looking for some input as to how I can customize the functionality of the cross-references in Word further. I've done a bunch of searching, but so far nothing seems to have directly addressed my question.
I have a technical report I'm writing, and I'm using quite a few cross-references all throughout it. As it is currently, I can insert a cross-reference no problem, and it appears in the doc as "8.5.2", just as I intended. However, the way I'm hoping the reference would look is something like
"[See Section 8.5.2, p. 11]", or "[{Text String} {heading number ref}, {page number ref}]"
I can certainly do this by manually typing the text string first, then inserting the heading cross-reference, and then inserting the page number cross-reference, but with the number of times I need to insert a reference like this, being able to output the whole thing in one operation would save me a lot of time (especially if for some reason I need to go back and change the specific syntax/format of the reference later)
Appreciate any advice you guys have!
Reply With Quote
  #2  
Old 02-08-2016, 08:38 AM
Charles Kenyon Charles Kenyon is online now Define custom Cross-reference output format to include "static" text and pg numbers Windows 8 Define custom Cross-reference output format to include "static" text and pg numbers Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,124
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The way I would do this would be with a macro attached to a QAT button or keyboard shortcut; all of these would be saved in the document or template. I would have you pick the cross reference target and then insert your text and both the section and the page number. This is not something you can record. It is beyond my ability to simply rip off.
Reply With Quote
  #3  
Old 02-08-2016, 05:31 PM
macropod's Avatar
macropod macropod is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 7 64bit Define custom Cross-reference output format to include "static" text and pg numbers Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use a macro like:
Code:
Sub InsertXrefWithPage()
Dim StrNm As String
Dialogs(wdDialogInsertCrossReference).Display
With Selection
  .Start = .Start - 1
  If .Fields.Count = 0 Then Exit Sub
  StrNm = "PAGE" & Trim(.Fields(1).Code.Text)
  .InsertAfter " on page "
  .Collapse wdCollapseEnd
  .Fields.Add Range:=.Range, Type:=wdFieldEmpty, Text:=StrNm, PreserveFormatting:=False
End With
End Sub
and assign it to a shortcut key and/or add it to the QAT. The macro will add ' on page ' plus the page # when you exit the Insert_Cross_Reference dialog.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-03-2016, 01:56 PM
here4singin here4singin is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 7 64bit Define custom Cross-reference output format to include "static" text and pg numbers Office 2013
Novice
 
Join Date: Mar 2016
Posts: 2
here4singin is on a distinguished road
Default Need Macro Code

Hi,

I used the macro above to insert a cross reference to heading text with the page number. Thank you for providing this code. Although it inserted the page number after the heading text, it is the current page instead of the cross reference's page number.

I also needed the macro to make the heading text ONLY be a certain character style, and I wanted the Insert As Hyperlink option selected when the dialog opened. My macro needs help. So far, it does this:

1. Opens the Insert Cross Reference dialog with the Insert as Hyperlink check box selected.
2. Lets me choose and insert the heading text I want to display.
3. When I press Close, it changes the whole thing to a character style called Character Hyperlink for Cross References, and it adds a page number in parenthesis.

My problem is with #3. I need only the heading text (not the page number) to be Character Hyperlink for Cross References. I need the rest of the text "(page X)" to be the current paragraph's style (not Character Hyperlink for Cross References). Lastly, I need the page number to go to the correct page (not the current page).

Example: Running with Bears (page 67)

Can you help rewrite this macro? I'm afraid I've reached the limit of my first-time macro user capabilities. I only got this far with help from a developer.

Thank you! Here is my macro so far:

Sub InsertXrefWithPage()
Dim StrNm As String
Dim Dlg As Dialog
Set Dlg = Dialogs(wdDialogInsertCrossReference)
Dlg.InsertAsHyperLink = 1
Dlg.Display
With Selection
Dim CurrentStyle As Style
Set CurrentStyle = .Style
.Start = .Start - 1
.Style = "Character Hyperlink for Cross References"
If .Fields.Count = 0 Then Exit Sub
StrNm = "PAGE" & .Fields(1).Code.Text
.InsertAfter " (page "
.Collapse wdCollapseEnd
Dim addedField As Field
Set addedField = .Fields.Add(Range:=.Range, Type:=wdFieldEmpty, Text:=StrNm, PreserveFormatting:=False)
.InsertAfter ")"
addedField.Select
.Style = CurrentStyle


End With
End Sub

Last edited by here4singin; 03-03-2016 at 01:58 PM. Reason: Woops forgot the macro code
Reply With Quote
  #5  
Old 03-04-2016, 03:36 PM
here4singin here4singin is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 7 64bit Define custom Cross-reference output format to include "static" text and pg numbers Office 2013
Novice
 
Join Date: Mar 2016
Posts: 2
here4singin is on a distinguished road
Default Resolved

^^ see my post above ^^
With dev help, I now have a working macro! Here ya go:

Sub InsertXrefWithPage()
Dim StrNm As String
Dim Dlg As Dialog
Set Dlg = Dialogs(wdDialogInsertCrossReference)
Dlg.InsertAsHyperLink = 1
Dlg.Display
With Selection
Dim CurrentStyle As Style
Set CurrentStyle = .Style
.Start = .Start - 1
.Style = "insertnameofyourstylehere"
If .Fields.Count = 0 Then Exit Sub
StrNm = "PAGE" & LTrim(.Fields(1).Code.Text)
.Collapse wdCollapseEnd
.InsertAfter " (page "
.Style = CurrentStyle
.Collapse wdCollapseEnd
Dim addedField As Field
Set addedField = .Fields.Add(Range:=.Range, Type:=wdFieldEmpty, Text:=StrNm, PreserveFormatting:=False)
.InsertAfter ") "
End With
End Sub

The result is Running with Bears (page 67).
Reply With Quote
  #6  
Old 01-07-2022, 08:02 AM
Tasmd3vil Tasmd3vil is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 10 Define custom Cross-reference output format to include "static" text and pg numbers Office 2019
Novice
 
Join Date: Jan 2022
Posts: 1
Tasmd3vil is on a distinguished road
Question header number instead of page

Quote:
Originally Posted by macropod View Post
You could use a macro like:
Code:
Sub InsertXrefWithPage()
Dim StrNm As String
Dialogs(wdDialogInsertCrossReference).Display
With Selection
  .Start = .Start - 1
  If .Fields.Count = 0 Then Exit Sub
  StrNm = "PAGE" & Trim(.Fields(1).Code.Text)
  .InsertAfter " on page "
  .Collapse wdCollapseEnd
  .Fields.Add Range:=.Range, Type:=wdFieldEmpty, Text:=StrNm, PreserveFormatting:=False
End With
End Sub
and assign it to a shortcut key and/or add it to the QAT. The macro will add ' on page ' plus the page # when you exit the Insert_Cross_Reference dialog.
Hi,

I'm highly interested in the code given by macropod. My only problem is, I would like to combine the header text together with it's header number instead of the page, like in this macro given. Does somebody have an idea?

Thanks in advance ,
Kay
Reply With Quote
  #7  
Old 01-10-2022, 05:05 PM
Guessed's Avatar
Guessed Guessed is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 10 Define custom Cross-reference output format to include "static" text and pg numbers Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

What do you mean by 'header text' and 'header number'. The headers on pages could include all sorts of content and we can't see what you are talking about as you haven't posted a document to illustrate.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 07-19-2022, 05:15 AM
Aussie_Z Aussie_Z is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 10 Define custom Cross-reference output format to include "static" text and pg numbers Office 2021
Novice
 
Join Date: Jul 2022
Posts: 2
Aussie_Z is on a distinguished road
Default

I'd like to ask a related follow-on question. Is this macro appropriate to be modified, or can someone suggest how I might, 1) using a Word document like this:

1.0 Heading 1
1.1 Heading 2
2.0 Heading 3

2) When selecting a heading cross-reference, output the following cross reference hyperlinks

Section 1.0, Heading 1

OR

3) What I am really trying to do is have the macro ask for a heading number (e.g., 1.0) and have the VBA put, in the current document location, the heading hyperlinks
(e.g., "Section 1.0, Heading 1")


Sub InsertXrefWithPage2()
Dim StrNm As String
Dim Dlg As Dialog

Set Dlg = Dialogs(wdDialogInsertCrossReference)
Dlg.InsertAsHyperLink = 1
Dlg.Display

With Selection

Dim CurrentStyle As Style
Set CurrentStyle = .Style
.Start = .Start - 1

If .Fields.Count = 0 Then Exit Sub

StrNm = "PAGE" & LTrim(.Fields(1).Code.text)
.Collapse wdCollapseEnd
.InsertAfter ", "
.Style = CurrentStyle
.Collapse wdCollapseEnd

Dim addedField As Field
End With

End Sub
Reply With Quote
  #9  
Old 01-17-2023, 01:49 PM
firstnamelast firstnamelast is offline Define custom Cross-reference output format to include "static" text and pg numbers Mac OS X Define custom Cross-reference output format to include "static" text and pg numbers Office 2016 for Mac
Novice
 
Join Date: Jan 2023
Posts: 1
firstnamelast is on a distinguished road
Default

Inspired by examples here and elsewhere, I created what I've wanted to have for ages
- ask for a section number (input box)
- enter a formatted cross-reference:
Quote:
section x.y.z 'name' (page xx)
Maybe it's useful for someone else too.
Keywords: VBA insert cross-reference formatted fields

Code:
Public Sub InsertParagraphReference()
'   code to ask for a paragraph reference (number)
'   and enter a formatted cross-reference (set of fields) in the document at current position

    Dim count As Integer
    Dim i As Integer
    Dim strSectionNumber As String
    Dim strHeader As String
    Dim myHeadings As Variant
    
    ' ask for number
    strSectionNumber = InputBox("Section number for formatted cross-reference", "Cross-reference")
        
    If Len(strSectionNumber) > 0 Then
        'get array of headings
        myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)
        count = 0
        For i = 1 To UBound(myHeadings)
            'see if entered string is this heading
            strHeader = Trim(myHeadings(i))
            If Left(Trim(myHeadings(i)), Len(strSectionNumber)) = strSectionNumber Then
                count = count + 1
                'enter formatted cross-reference
                With Word.Selection
                    .InsertAfter "section "
                    .Collapse Direction:=wdCollapseEnd
                    'section number
                    .insertCrossReference _
                        ReferenceType:=wdRefTypeNumberedItem, _
                        ReferenceKind:=wdNumberFullContext, ReferenceItem:=i, _
                        InsertAsHyperlink:=True, IncludePosition:=False
                    .Collapse Direction:=wdCollapseEnd
                    'section header title'
                    .InsertAfter " '"
                    .Collapse Direction:=wdCollapseEnd
                    .insertCrossReference _
                        ReferenceType:=wdRefTypeNumberedItem, _
                        ReferenceKind:=wdContentText, ReferenceItem:=i, _
                        InsertAsHyperlink:=True, IncludePosition:=False
                    .Collapse Direction:=wdCollapseEnd
                    .InsertAfter "'"
                    .Collapse Direction:=wdCollapseEnd
                    'page number
                    .InsertAfter " (page "
                    .Collapse Direction:=wdCollapseEnd
                    .insertCrossReference _
                        ReferenceType:=wdRefTypeNumberedItem, _
                        ReferenceKind:=wdPageNumber, ReferenceItem:=i, _
                        InsertAsHyperlink:=True, IncludePosition:=False
                    .Collapse Direction:=wdCollapseEnd
                    .InsertAfter ")"
                    .Collapse Direction:=wdCollapseEnd
                End With
                Exit Sub
            End If
        Next i
        'notify if not found
        If count = 0 Then
            i = MsgBox("Could not find " & Chr(34) & strSectionNumber & Chr(34) & " as section number (enter in 'x.y.z' format)", vbOKOnly + vbExclamation)
        End If
    End If
End Sub
Reply With Quote
  #10  
Old 01-17-2023, 02:42 PM
Aussie_Z Aussie_Z is offline Define custom Cross-reference output format to include "static" text and pg numbers Windows 10 Define custom Cross-reference output format to include "static" text and pg numbers Office 2021
Novice
 
Join Date: Jul 2022
Posts: 2
Aussie_Z is on a distinguished road
Cool section x.y.z 'name' (page xx) – Finally ... SOLVED!!!

firstnamelast ... Thanks. That is the bomb!!!

Exactly what I was looking for ...
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Define custom Cross-reference output format to include "static" text and pg numbers Add static text to cross-reference tfa91 Word 7 10-09-2019 07:15 AM
Define custom Cross-reference output format to include "static" text and pg numbers Making cross-reference say "Fig." instead of "Figure" dgalb Word 17 11-09-2014 06:25 AM
Define custom Cross-reference output format to include "static" text and pg numbers Reference number and cross reference for equation numbers to match the thesis format wmac Word 1 05-14-2013 08:54 PM
Cross Reference Heading Number with the word "Section" included bblouin Word 5 12-20-2012 05:27 PM
Define custom Cross-reference output format to include "static" text and pg numbers Is there a way to make the cross-refernce format to be "Only lable and number"? Jamal NUMAN Word 1 04-10-2011 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft