Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-17-2022, 10:15 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 Footnote References Before Punctuation

Hi Macropod, thank you for providing the code. I am getting error 5904 on the first .Characters.Last.Next.Delete - should I be changing [!0-9A-Za-z] to [.,;:]? I have attached a stripped down version of a few pages of the contracts I am working on for ease. I only need to move the footnote before a square bracket field if they appear at the end of paragraphs and not within the paragraph itself.

footnote test doc.docx

Code:
Sub FootnotePunctBefore()
Application.ScreenUpdating = False
Dim FtNt As Footnote, Rng As Range, Fld As Field
With ActiveDocument
  For Each FtNt In .Footnotes
    Set Rng = FtNt.Reference
    With Rng
      'Eliminate any spaces before the footnote
      Do While .Characters.First.Previous Like "[ " & Chr(160) & "]"
        .Characters.First.Previous.text = vbNullString
      Loop
      'Swap the footnote/punctuation, as applicable
      Do While .Characters.Last.Next Like "[!0-9A-Za-z]"
        .InsertBefore .Characters.Last.Next
        .Characters.Last.Next.Delete
      Loop
    End With
  Next
  For Each Fld In .Range.Fields
    With Fld
      If .Type = wdFieldNoteRef Then
        'Swap the footnote/punctuation, as applicable
        With .Result
          Do While .Characters.First.Previous Like "[ " & Chr(160) & "]"
            .Characters.First.Previous.text = vbNullString
          Loop
          'Swap the footnote/punctuation, as applicable
          Do While Not .Characters.Last.Next Like "[0-9A-Za-z]"
            .InsertBefore .Characters.Last.Next
            .Characters.Last.Next.Delete
          Loop
        End With
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
 

Thread Tools
Display Modes


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 10:06 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