![]() |
|
![]() |
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
![]()
I am trying to devise a workflow to convert manual cross references in footnotes to other footnotes to automatic cross references. Due to a limitation in Word's Find and Replace in replacing with field codes, I am stuck. I understand that Find and Replace opertions can be performed with a macro without the limitation.
I have very limited ability in VBA coding, and I appreciate any help I can get. My workflow comrpises of the following steps: 1. Make bookmarks of all footnote references in the body text using a modified version of the macro posted by MattP at wordbanter at http://www.wordbanter.com/showthread.php?t=124842) The bookmarks created are named "Bookmark 1", "Bookmark 2" and so on and match the numbering of the footnote reference. 2. Now I need to replace all instances of the manual cross refs in the footnotes with the { FTNREF Bookmark X } field code. The manual cross refs follow this notation consistently: "see n X". The problem is that Word's Find and Replace only recognize the field opening and closing braces "^d" in the Find box, but not in the Replace box. The best I can do is to copy the "{FTNREF Bookmark" field (it this partial form) to clipboard, and then replace "see n" with "^c". But I need the number that comes after the "see n" to be within the field code after "Bookmark". So for e.g. "see n 8", would be replaced with "{FTNREF Bookmark8}". The problem is that after I replace replace "see n" with "^c", the number that comes after "see n" is outside of the "{FTNREF Bookmark" field code. Can anyone help with a macro to do such a find and replace operation? Thanks. |
#2
|
||||
|
||||
![]()
I can't see the point of bookmarking all the footnotes, since Word creates its own when you insert cross-references to them, which you ordinarily do via a NOTEREF field.
A macro to do what you're after using Word's own footnote referencing is: Code:
Sub ActivateFootNoteCrossRefs() Dim SBar As Boolean Dim TrkStatus As Boolean Dim Rng As Range, i As Long, StrNt As String ' Store current Status Bar status, then switch on SBar = Application.DisplayStatusBar Application.DisplayStatusBar = True ' Store current Track Changes status, then switch off With ActiveDocument TrkStatus = .TrackRevisions .TrackRevisions = False End With ' Turn Off Screen Updating Application.ScreenUpdating = False With ActiveDocument ' Process all footnotes For i = 1 To .Footnotes.Count ' Update the statusbar StatusBar = "Processing Footnote " & i Set Rng = .Footnotes(i).Range With .Footnotes(i).Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "see n [0-9]{1,}" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found If .Duplicate.InRange(Rng) Then StrNt = Split(.Duplicate.Text, " ")(2) ' To replace the "see n " text as well as the number with ' a formatted footnote reference, delete/comment-out the next ' line and change wdFootnoteNumber to wdFootnoteNumberFormatted .Start = .Words(3).Start .InsertCrossReference ReferenceType:=wdRefTypeFootnote, _ ReferenceKind:=wdFootnoteNumber, ReferenceItem:=StrNt .Collapse wdCollapseEnd .Find.Execute Else Exit Do End If Loop End With Next ' Update the statusbar StatusBar = "Finished Processing " & .Footnotes.Count & " Footnotes" End With Set Rng = Nothing ' Restore original Status Bar status Application.DisplayStatusBar = SBar ' Restore original Track Changes status ActiveDocument.TrackRevisions = TrkStatus ' Restore Screen Updating Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
Cross-posted at: http://www.vbaexpress.com/forum/show...ith-field-code
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
Dear Paul,
Thanks for your help. First, apologies for the breach of etiquette in cross posting. I did not realize there was a norm against it. The reason why I used bookmarks instead of footnote cross references was simply because I did not know how to batch create the latter by macro, and I found a macro that uses the former. I tried your macro on a simple test page. Unfortunately, it did not seem to work - with or without changing wdFootnoteNumber to wdFootnoteNumberFormatted I've taken a screenshot of the page ![]() In this test doc, the cross references in the footnotes to other footnotes are manually typed in. I am trying to convert them to automatic cross references. |
#5
|
||||
|
||||
![]()
Your screenshot displays as simply a boxed X. The code works fine for what you described in your post. It replaces all instances of 'see n X' in footers, where X is a number.
Since you're not getting the results you desire, perhaps you could attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
Hi Paul,
This is the doc which I ran your marco on. I created this test doc just to narrow down why the macro wasn't working in the other longer, more complicated doc. It doesn't seem to be converting the manual footnote references to the cross reference fields in this simple test doc as well. Regards, Jay |
#7
|
||||
|
||||
![]()
The simple reason is that your document content differs from the description in your post. The Find expression is case-sensitive, to match the lower-case "see n" mentioned three times in your original post. That isn't the same as the "See n" in your document. You can process both by changing:
.Text = "see n [0-9]{1,}" to: .Text = "[Ss]ee n [0-9]{1,}"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Dear Paul,
It works brilliantly. Thank you. Much obliged. Regards, Jay |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jessy_33 | Word | 1 | 05-07-2014 02:45 PM |
![]() |
Suchoklates | Word | 1 | 09-19-2013 02:32 AM |
![]() |
acolussi | Word | 9 | 05-16-2013 02:11 AM |
Cross References not hyperlinked in .HTM | GreyOne | Word | 2 | 03-08-2013 01:35 AM |
Cross References | egcharles | Office | 0 | 04-19-2009 06:20 AM |