Wildcard compare in VBA

S

Soren

Hi

This is probably a simple question. I am trying to write
a macro that will run some code based on a Window name.

This is the line I use:
If WndwName Like "Letter" & "*" Then (do something)

So if the wndow name is "Letter1 to Alice", it will run.

However it will also run if the window name is "Letterman"

I want my code to just run if the word Letter is followed
by a number, how do I do that?

Thanks in advance
Soren
[email protected]
 
J

Jay Freedman

Hi Soren,

You had only to look at the VBA help topic about the Like operator. It
plainly states there that the character # in a pattern matches any digit,
and the character * matches zero or more characters (of any kind). You can
use the statement

If WndwName Like "Letter#*" Then
 
G

Guest

Sometimes the solution is right in front of you. Thank
you for the help, I'll try to use the help next time :)

Soren
 
Top