Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Member
 
Posts: 70
Default Reference workbook with a certain word in the name

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:

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!
  #2   Report Post  
Member
 
Posts: 70
Default

Quote:
Originally Posted by KeriM View Post
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:

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!
Did some more digging and solved my own problem...

Code:
Dim ws As Workbook
For Each ws In Workbooks
    If ws.Name Like "*Count*" then Windows(ws.Name).Activate
Next
  #3   Report Post  
Senior Member
 
Posts: 663
Default

Quote:
Originally Posted by KeriM View Post
Did some more digging and solved my own problem...

Code:
Dim ws As Workbook
For Each ws In Workbooks
    If ws.Name Like "*Count*" then Windows(ws.Name).Activate
Next
Well done, KeriM.

Most people when they find the answer themselves just abandon the post and leave people working on it for them.
  #4   Report Post  
Member
 
Posts: 70
Default

Quote:
Originally Posted by Spencer101 View Post
Well done, KeriM.

Most people when they find the answer themselves just abandon the post and leave people working on it for them.
Thanks. I try to be courteous to everyone answering these. I also hate when I'm searching for an answer and the post is incomplete, so if I find an answer, I like to post it to benefit others.
  #5   Report Post  
Senior Member
 
Posts: 663
Default

Quote:
Originally Posted by KeriM View Post
Thanks. I try to be courteous to everyone answering these. I also hate when I'm searching for an answer and the post is incomplete, so if I find an answer, I like to post it to benefit others.
If only there were more out there like you Keri ;)


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Reference workbook with a certain word in the name

KeriM wrote:

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

--
- How anticlimatic.
- Well, we're out of real estate!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Data to Word 2007 Using Reference to Word 11.0 Library Orion Cochrane Excel Programming 1 December 12th 08 03:00 PM
replace a word with another word through out workbook adam Excel Worksheet Functions 3 December 8th 08 11:25 PM
How to check workbook is already opened before passing the workbook obj to a subroutine in Word Bon Excel Programming 2 January 19th 06 09:54 AM
word reference GUS Excel Programming 1 September 1st 03 03:39 AM
word reference GUS Excel Programming 0 August 31st 03 08:32 PM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"