PDA

View Full Version : [SOLVED:] Delete all spaces before footnote and endnotes call numbers



ma_roberge
10-19-2016, 08:58 AM
I am writing a macro that will delete all superfluous spaces before footnote call numbers (^f). Ideally it should also delete such spaces before endnote call numbers (^e) and take care of both normal and unbreakable spaces. It appears that the generic characters option cannot be checked with these codes. The superflous spaces are stripped to a single one by the forum software in the following example.

Example: This is a line of text with superflous spaces before the footnote call number. 1

My current code locks the program. How can one check the previous character? This seems to be what causes the difficulty. Thanks in advance for any help.


Sub DeleteSpacesBeforeCallNumbers()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^f"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute = True
Selection.Collapse
While Selection = " "
Selection.TypeBackspace
Wend
Loop
Selection.MoveRight Unit:=wdCharacter, Count:=1 'Moves the cursor past the call number to continue searching.
End Sub

gmaxey
10-19-2016, 06:28 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oFN As Footnote
For Each oFN In ActiveDocument.Footnotes
Do While oFN.Reference.Characters.First.Previous Like "[" & Chr(32) + Chr(160) & "]"
oFN.Reference.Characters.First.Previous.Delete
Loop
Next
lbl_Exit:
Exit Sub
End Sub

ma_roberge
10-20-2016, 07:05 AM
Greg,

Thank you for solving my problem with such efficient code. I could expand it easily to deal with endnotes as well.