Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-17-2022, 06:16 AM
Shelley Lou Shelley Lou is offline VBA Move Footnote References Before Punctuation Windows 10 VBA Move Footnote References Before Punctuation Office 2016
Expert
VBA Move Footnote References Before Punctuation
 
Join Date: Dec 2020
Posts: 259
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Move Footnote References Before Punctuation Footnote references in the footnote section losing their style when cut+pasted from same doc emblaw Word 4 12-08-2020 06:23 AM
VBA Move Footnote References Before Punctuation Fix footnote and endnote references to arabic numbers everywhere? KDuncan Word 6 04-28-2020 12:14 AM
VBA Move Footnote References Before Punctuation Word Find won't move out of footnote michaelbriordan Word 3 06-17-2015 10:12 AM
VBA Move Footnote References Before Punctuation How do I keep footnote references and text on the same page bearligirl89 Word 3 11-20-2013 03:33 PM
VBA Move Footnote References Before Punctuation Multiple footnote references jimgard Word 1 07-23-2013 11:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:33 AM.


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