mr3k
mr3k

Reputation: 366

VBA - Use wildcards to find correct string

I have a macro that use the Find function to find the string that starts with number / number number etc.. Example:
1/2313-gergre....
4/5385-gewsgergeo....

I tried following without success:

    StartString = "#/#"
    With Rng.Find
    .MatchWildcards = True
        Do While .Execute(findText:=StartString, Forward:=False) = True
            MsgBox ("Found")

        Loop
    End With

It works if I use *, but I only want to accept numbers..

Upvotes: 0

Views: 6380

Answers (1)

Julian
Julian

Reputation: 1471

Just do this:

Set myRange = ActiveDocument.Content
StartString = "[0-9]/[0-9]"
    With myRange.Find
    .MatchWildcards = True
        Do While .Execute(findText:=StartString, Forward:=False) = True
            MsgBox ("Found")

        Loop
    End With

Here's an link with other wildcard options

Upvotes: 1

Related Questions