Solved

How to reference an open workbook using wildcard in VBA

Posted on 2007-03-29
4
1,236 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now