Solved

How to reference an open workbook using wildcard in VBA

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

776 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