View Single Post
 
Old 08-17-2022, 06:16 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA Move Footnote References Before Punctuation

I have been given quite a few 200 page contract documents to house style/format each containing over 300 footnotes. I recorded a find and replace to move the punctuation before the footnotes refs - but when I added code to remove spaces before footnotes refs it stopped working.

Code:
.text = "([.,:;\?\!])(^2)"
Another issue is that if the sentence/paragraph ends with a square bracket in a field it will only move the footnote ref if its not in a field and I don't know how to tell the code to do both. Some might end with double square brackets in fields which makes it even more confusing.

What have I missed from the code to make it work correctly.

Capture.PNG

Code:
Sub MoveFootnotesBeforePunctuation()
Dim oRng As Range, oFN As Footnote
  For Each oFN In ActiveDocument.Footnotes 'Remove spaces before footnote refs
    Do While oFN.Reference.Characters.First.Previous Like "[" & Chr(32) + Chr(160) & "]"
      oFN.Reference.Characters.First.Previous.Delete
    Loop
  Next
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "([.,:;\?\!])(^2)"       'Move footnote refs before punctuation
.Replacement.text = "\2\1"
.text = "([\]])(^2)(^13)"        'Move footnote refs before square brackets end of paras
.Replacement.text = "\2\1\3"
.text = "([.;:])([\]])(^2)(^13)" 'Move footnote refs before square brackets and punctuation
.Replacement.text = "\3\2\1\4"
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End With
End Sub
Reply With Quote