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
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