Editing footntoes revisited, more help needed

D

Dorak

Dave Lett was kind to help me with a footnote editing issue, the original
post was dated 1/26/2010. Essentially, he created a macro to replace either
a space or a tab that precedes footnote text with two spaces.

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 to two spaces.

Any advice on how to do that?
 
D

Doug Robbins - Word MVP

So as to avoid re-inventing the wheel, show us the code of the macro that
Dave developed and we may be able to suggest a modification.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
C

CJ

Here's the 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

Doug Robbins - Word MVP

I think the following may do what you want:

Dim s As Integer
Dim rng As Range
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
With Selection
.Collapse Direction:=wdCollapseStart
Set rng = Selection.Range
rng.Start = rng.Paragraphs(1).Range.Start
rng.Select
If Right(Selection.text, 1) = " " Then
Selection.Collapse wdCollapseEnd
Selection.TypeBackspace
End If
End With
Next
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
If Left(Selection.text, 1) = vbTab Then
Selection.text = " " & Mid(Selection.text, 2)
Else
With Selection
.Collapse Direction:=wdCollapseStart
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.text = Chr(32) Then .TypeText text:=" "
End With
End If
Next


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
C

CJ

Unfortunately, if the footnote text is preceded by one space, this macro
removes it and leaves the footnote reference and footnote text right up
against each other.
The objective is:


If one space precedes footnote text, then change to two spaces
If tab precedes footnote text, then change to two spaces
If one space and a tab precedes footnote text, change to two spaces

And ideally, if nothing precedes footnote text, then add two spaces
 
D

Doug Robbins - Word MVP

OK, Try

Dim s As Integer
Dim rng As Range
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
With Selection
.Collapse Direction:=wdCollapseStart
Set rng = Selection.Range
rng.Start = rng.Paragraphs(1).Range.Start
rng.Select
End With
Next
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
If Left(Selection.text, 1) = vbTab And Selection.Start <>
Selection.Paragraphs(1).Range.Start + 1 Then 'Or Left(Selection.text, 1) = "
"
Selection.text = " " & Mid(Selection.text, 2)
ElseIf Left(Selection.text, 1) = vbTab Then
Selection.text = " " & Mid(Selection.text, 2)
Else
With Selection
.Collapse Direction:=wdCollapseStart
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.text = Chr(32) Then .TypeText text:=" "
End With
End If
Next


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
D

Doug Robbins - Word MVP

Probably a line break inserted by the mail program.

In the following, I have inserted a Visual Basic Line Break "character" ( _)
that should overcome the issue.

Dim s As Integer
Dim rng As Range
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
With Selection
.Collapse Direction:=wdCollapseStart
Set rng = Selection.Range
rng.Start = rng.Paragraphs(1).Range.Start
rng.Select
End With
Next
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
If Left(Selection.text, 1) = vbTab And Selection.Start <> _
Selection.Paragraphs(1).Range.Start + 1 Then
Selection.text = " " & Mid(Selection.text, 2)
ElseIf Left(Selection.text, 1) = vbTab Then
Selection.text = " " & Mid(Selection.text, 2)
Else
With Selection
.Collapse Direction:=wdCollapseStart
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.text = Chr(32) Then .TypeText text:=" "
End With
End If
Next

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
C

CJ

Thanks Doug, that works very nicely. Do you have any idea how we would deal
with footnote text that is preceded by nothing? If nothing before, insert
two spaces?
I know I'm asking a lot, and I really appreciate every response!
 
D

Doug Robbins - Word MVP

I believe that this handles all the cases that you have come up with:

Dim s As Integer
Dim rng As Range
For s = 1 To ActiveDocument.Footnotes.Count
ActiveDocument.Footnotes(s).Range.Select
Set rng = Selection.Paragraphs(1).Range
If Selection.Start = rng.Start + 1 Then
Selection.Text = " " & Selection.Text
End If
If Left(Selection.Text, 1) = vbTab And Selection.Start <> _
Selection.Paragraphs(1).Range.Start + 1 Then
Selection.Text = " " & Mid(Selection.Text, 2)
ElseIf Left(Selection.Text, 1) = vbTab Then
Selection.Text = " " & Mid(Selection.Text, 2)
Else
With Selection
.Collapse Direction:=wdCollapseStart
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Text = Chr(32) Then .TypeText Text:=" "
End With
End If
Next


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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