Wildcard to activate another window

R

Rob

Hello. I'm trying to make another window active which will have the file
name of "WIPDrilldownExport(__).xls", where only one character appears in the
parentheses and could be a 1, 2, or 3. The line

Windows("WIPDrilldownExport(#).xls").Activate

doesn't work. Thanks in advance.
 
D

Dave Peterson

Option Explicit
Sub testme()
Dim myWindow As Window
For Each myWindow In Application.Windows
If LCase(myWindow.Caption) Like LCase("WIPDrilldownExport(?).xls") Then
myWindow.Activate
Exit For
End If
Next myWindow
End Sub

I usually go through the workbooks collection so I don't have to worry about any
modifications to the window's caption:

Option Explicit
Sub testme()
Dim wkbk As Workbook
For Each wkbk In Application.Workbooks
If LCase(wkbk.Name) Like LCase("WIPDrilldownExport(?).xls") Then
wkbk.Activate
Exit For
End If
Next wkbk
End Sub
 
J

Jacob Skaria

A procedure to activate the window using a search string. If you are sure
there is not other workbook opened which contain the numeric 1 you can usel
this as
ActivateBookwithKeyword ("1")


Sub ActivateBookwithKeyword(strSearch As String)
For intTemp = 1 To Workbooks.Count
If InStr(1, Workbooks(intTemp).Name, strSearch, 1) <> 0 Then
Workbooks(intTemp).Activate
Exit Sub
End If
Next
End Sub


If this post helps click Yes
 

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