View Single Post
 
Old 08-29-2018, 05:50 PM
risomd risomd is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Aug 2018
Posts: 6
risomd is on a distinguished road
Default Removing trailing spaces from footnotes

I am looking for a way to remove any trailing spaces from all footnotes.
I thought I would try to iterate through them and check if the last character was a space (or other) and delete it, but this isn't working.

It also throws a "Cannot edit Range" Error if the last character of a footnote is within a Hyperlink's text (blue and underlined) and is a space.

What is the right way to approach this? Footnotes can have multiple hyperlinks and the last character may be within one of them and be a space or other character I want rid of?


I've also tried just .Find'ing within the footnote's range, but I can't seem to only remove the trailing space(s).


Some sample code that fails:

Code:
For i = 1 To ActiveDocument.Footnotes.Count

   Dim fn As Object
   Set fn = ActiveDocument.Sections(1).Range.Footnotes(i)
   myMax = fn.Range.Characters.Count
   For j = myMax To 1 Step -1
      
       myChar = fn.Range.Characters(j)
        
        If myChar = Chr(32) Then
            myLong = fn.Range.Characters(j).Delete
           'This fails if last char is space within a hyperlink
        Else
            Exit For
        End If
   
    Next

Next
Reply With Quote