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
(e-mail address removed)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top