Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do I Find 2 strings (Word 2002 XP SR3)

    New requirements means I now have to search for 2 text strings, find one, or the other string and then perform the same code.

    The strings are "TAX INVOICE" or "CREDIT NOTE"

    i have the below code which currently performs one string search...


    strSearchText = "TAX INVOICE"

    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Font.Bold = True

    With Selection.Find
    .Text = strSearchText
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    Selection.Find.Execute
    While Selection.Find.Found


    Would I use a wildcard? Im not familiar with how to work with wildcards

    many thanks

    diana

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: how do I Find 2 strings (Word 2002 XP SR3)

    It would be simplest to perform two searches rather than try to craft a single, all-inclusive search. That's not to say it can't be done, but it would be tricky. For example, first character either T or C, second character either A or R...

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I Find 2 strings (Word 2002 XP SR3)

    tnx Jefferson

    I'll implement hte simple approach...being perform two searches

    tnx again

    dd

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: how do I Find 2 strings (Word 2002 XP SR3)

    You could create a procedure with the search string as argument:

    Sub SearchForText(strSearchText As String)
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .ClearFormatting
    .Font.Bold = True
    .Text = strSearchText
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
    Do While .Found
    ...
    Loop
    End With
    End Sub

    You can then call it twice in your macro:

    Call SearchForText("TAX INVOICE")
    Call SearchForText("CREDIT NOTE")

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do I Find 2 strings (Word 2002 XP SR3)

    many thanks Hans

    I'll look into this....

    diana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •