Reference workbook with a certain word in the name

K

KeriM

I need to reference an open workbook in my code but the name change
periodically; however, it always has the word "count" in it. Is there
way to reference a workbook by a certain word in the name? This is wha
I have so far:


Code
-------------------

Dim ws As Workbook
If ws.Name Like "*count*" Then ws.Activate

-------------------


I think I need a "set" somewhere, but I'm not sure what to "set" it as


Any help is appreciated. Thanks
 
A

Auric__

KeriM said:
I need to reference an open workbook in my code but the name changes
periodically; however, it always has the word "count" in it. Is there a
way to reference a workbook by a certain word in the name? This is what
I have so far: [snip]
I think I need a "set" somewhere, but I'm not sure what to "set" it as.

Try something like this:

For Each ws In Workbooks
If InStr(1, ws.Name, "count", vbTextCompare) Then
'...whatever you need to do to ws...
'If there's only one wb named *count* then finish with this:
Exit For
End If
Next
 

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