View Single Post
 
Old 04-10-2014, 05:40 PM
TimFromPhx TimFromPhx is offline Windows 7 32bit Office 2007
Novice
 
Join Date: Apr 2014
Posts: 4
TimFromPhx is on a distinguished road
Default Is there a quicker way to search?

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

Last edited by macropod; 04-10-2014 at 06:51 PM. Reason: Added code tags & formatting
Reply With Quote