View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default activating windows

Matthew Dyer laid this down on his screen :
Currently, I am using the following code to activate a window
contatining data to copy from -

Windows("rwservlet").Activate


Only problem is sometimes there is additional info after rwservlet
(Ex: rwservlet [2], rwservlet [Read-Only], etc). How would I put in a
wildcard so that any rwservlet..... window would work with the above
code?


Try...

Function GetWkbNameFromWindow(TextIn As String) As String
Dim wnd As Window
For Each wnd In Application.Windows
If InStr(1, wnd.Caption, TextIn, vbTextCompare) 0 Then _
GetWkbNameFromWindow = wnd.Caption: Exit Function
Next
End Function

Example usage:

Sub DoStuff()
Dim sName As String
sName = GetWkbNameFromWindow("rwservlet")
If Not sName = "" Then Workbooks(sName).Activate
'...more code
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc