• Case Insensitive find w/ wildcards

    • This topic has 4 replies, 3 voices, and was last updated 24 years ago.
    Author
    Topic
    #354973

    I’m working with an existing VBA application that the users are requesting adding the capability of using wildcards in their find/replace search. I can change the following code to allow wildcards…but the search becomes case sensitive. Is there a way to avoid this?

    Private Sub SetSearchCriteria()
    With Selection.Find
    .ClearFormatting
    .Replacement.Text = vbNullString
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False –> True allows wildcards
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    End Sub

    Viewing 1 reply thread
    Author
    Replies
    • #522680

      Hi bitram:

      I’m not a VBA expert, but I can tell you that when you do a search using Wildcards, the match case checkbox becomes dimmed. If you want to search for both upper & lowercase, you use an expression such as, [a-zA-Z]. This searches for both upper & lower.

      Hope this helps.

      • #522684

        Thanks for the quick response Phil!

        Using your example… If I was searching for the word ‘string’, how would I implement that?…
        – in the find box type [a-zA-Z]string – ??
        – in the find box type [a-zA-Z]”string” – ??

        Michael

        • #522702

          Hi Michael:

          Well, that’s why I said I wasn’t a VBA expert. I know how to do a Find/Replace, but I don’t know what commands would execute what you want.

          If you were not using VBA, but using Find/Replace & wanted to find the word “string”, regardless of case, you wouldn’t tick “Use Wildcards”.

          But if you wanted to do it using the wildcard search engine, you would use:
          [sS][Tt][rR][Ii][nN][Gg]

    • #522841

      There is this thing in VBScript called the RegExp (regular expressions) object that lets you do case insensitive find and replace. I posted a sample procedure here. As noted in my additional comments on the other message, it’s not so hot for changes in a document because the formatting gets whacked.

      Another problem with using this kind of thing interactively is that the syntax is different than Word’s native wildcard replace. For example, you have to put a before a . or it is interpreted as “one character.” The list goes on. If you do end up coding this, I’d love to see a copy. I have attached another sample from a more recent project.

    Viewing 1 reply thread
    Reply To: Case Insensitive find w/ wildcards

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: