Solved

How to reference an open workbook using wildcard in VBA

Posted on 2007-03-29
4
1,437 Views
Last Modified: 2012-08-14
Hi all,

How do I activate a workbook (which is already open within the current application) for which I know part of the name? Like, I know that the workbook starts with: CMVINXBXINNNI_Index_MorningReport-
but the rest of the name is unknown (or will vary).

Example:
Windows("CMVINXBXINNNI_Index_MorningReport-20070329").Activate

How come I can not reference this workbook in the following manner:
Windows("CMVINXBXINNNI" & "*").Activate

Hope you can help :)
0
Comment
Question by:WileyPowers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 total points
ID: 18814777
Hi WileyPowers,

You can't use wildcards to reference a workbook, because there may be multiple workbooks with a similar name. You could use this function....

     Public Function GetWorkbook(strLike As String) As Workbook
          Dim wb As Workbook
          For Each wb In Application.Workbooks
               If wb.Name Like strLike Then
                    Set GetWorkbook = wb
                    Exit Function
               End If
          Next
     End Function

...and you'd use it like this....

     GetWorkbook("CMVINXBXINNNI" & "*").Activate

Note: If there are multiple workbooks with a similar name, the function will return the first one it finds.

Regards,

Wayne
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 8 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question