PDA

View Full Version : Solved: Test for a string in a active workbook name



Djblois
12-04-2008, 07:27 AM
How can I test for a string in an activeworkbooks name?

I tried this:

If activeworkbook.name = "*est*" then

I though a wildcard character would work but it didn't.

RonMcK
12-04-2008, 07:47 AM
Daniel,

Replace the "=" sign with LIKE. Here is what Help has to say:

"Like Operator Example (Microsoft Excel)
This example deletes every defined name that contains "temp". The Option Compare Text statement must be included at the top of any module that contains this example.

For Each nm In ActiveWorkbook.Names
If nm.Name Like "*temp*" Then
nm.Delete
End If
Next nm"

Cheers,

Djblois
12-04-2008, 07:58 AM
Thank you that worked perfectly. so whenever I want to use a wild character I need to use like?

RonMcK
12-04-2008, 08:01 AM
Yes, if you are searching for the existence of a substring within a test string.

Cheers,

Bob Phillips
12-04-2008, 08:04 AM
You can also use InStr



If InStr(nm.Name, "temp") > 0 Then