From: CJ on
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

From: DaveLett on
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
From: CJ on
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?

"DaveLett" wrote:

> 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
From: DaveLett on
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

"CJ" wrote:

> 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?
>
> "DaveLett" wrote:
>
> > 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
From: CJ on
You know what? You are absolutely awesome! Thank you for such quick and
expert help. It works exactly like I need it to.

"DaveLett" wrote:

> 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
>
> "CJ" wrote:
>
> > 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?
> >
> > "DaveLett" wrote:
> >
> > > 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