Editing Footnotes

C

CJ

How can I change how the footnotes appear at the bottom of the page in a
document that already exists with footnotes in it?

Issues are: (1) Sometimes there is one space, (2) sometimes there is a tab
before the footnote text -- both of which I think I've handled in the code
below, and (3) in rare occassions, there is no space before the footnote text
-- and I have no idea what to do in that case!

I want to programatically edit all footnotes to appear with two spaces
before the footnote text.

Can someone please take a look and advise me (1) have I dealt with the first
two issues properly? and (2) how to properly handle issue 3? I would be
ever so grateful for help!

Here is code:

Sub FixFootnotes()
Dim s As Integer
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
With Selection
.Collapse Direction:=wdCollapseStart
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Text = Chr(32) Then .TypeText Text:=" "
If Selection.Text = vbTab Then .TypeText Text:=" "
End With
Next
End Sub
 
D

DaveLett

Hi CJ,
I think you're looking for something like the following:

Dim lFoot As Long
Dim sFoot As String
Dim oRng As Range

For lFoot = 1 To ActiveDocument.Footnotes.Count
Set oRng = ActiveDocument.Footnotes(lFoot).Range.Paragraphs(1).Range
oRng.MoveStart unit:=wdCharacter
'''as long as the first character of the footnote is a space
'''or tab, delete that first character
Do While Left(oRng.Text, 1) = " " Or Left(oRng.Text, 1) = vbTab
oRng.Characters(1).delete
Loop
'''insert two spaces before each footnote 'text'
oRng.InsertBefore Text:=" "
Next lFoot

HTH,
Dave
 
C

CJ

Dave, this is beautiful! Thank you so much! Do you have any idea whether
there is a way to deal with the instance where there is no space before the
footnote text?
 
D

DaveLett

Hi CJ,
The provided routine accounts for that case with this line:

'''insert two spaces before each footnote 'text'
oRng.InsertBefore Text:=" "

Notice that this line comes after the closing "Loop" for removing
characters; therefore, the routine inserts two spaces before EVERY footnote.

HTH,
Dave
 
C

CJ

You know what? You are absolutely awesome! Thank you for such quick and
expert help. It works exactly like I need it to.
 
C

CJ

I just ran into one from an outside source where the footnote text is
preceded by a space and a tab, and the macro hangs there.

It looks like this is something we will have to start dealing with, because
we will be working with that outside source pretty frequently and must be
able to change it.

Any advice on how to do that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top