I created a form with the following code:
It works okay, but the process is too slow because I get too many false matches.
Code:
Public FootnoteCounter As Integer
Private Sub CurrentFootnote_Change()
FootnoteCounter = Me.CurrentFootnote.Value
End Sub
Public Sub FindFootnote_Click()
Selection.Find.ClearFormatting
With Selection.Find
.Text = FootnoteCounter
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
Public Sub DeleteFootnote_Click()
Selection.Delete
Selection.Find.ClearFormatting
With Selection.Find
.Text = FootnoteCounter
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
Public Sub IncrementCounter_Click()
FootnoteCounter = FootnoteCounter - 1
Me.CurrentFootnote.Value = FootnoteCounter
Selection.HomeKey Unit:=wdStory
End Sub
My code does one of the following functions: Find a match, Delete selection and find next match, Increment the counter.
I'm starting with the highest footnote number and working through backwards because it is quicker. For instance searching for "1" returns 1, 11, 141, 1990, etc. I get less errors if I search in reverse.
Can you think of a way to do a search for "1" that would not find 11, 141, 1990, etc?
Is there a way I could use a regular expression to do the search that would exclude numerals to the left or right of my target?
Thanks for all your help