View Single Post
  #10   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 :
On Mar 10, 3:14*pm, GS wrote:
Matthew Dyer was thinking very hard :





On Mar 10, 2:37 pm, GS wrote:
GS used his keyboard to write :


If Not sName = "" Then Workbooks(sName).Activate
change to...


If Not sName = "" Then Application.Windows(sName).Activate
--
Garry


Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
sorry garry, but it isnt working.


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


wnd comes back as Nothing and remains nothing throughout when the code
is run. I ran it with breaks. It also appears to be running only for
the 'active' window and not trying to pull data from any of the other
windows to find the match.


Are you using the function 'as posted'? It will only work if there's at
least 1 workbook open. If more then it steps through each window to
check if the string you passed is contained in its Caption. What are
you doing different that's making it NOT work?

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc- Hide quoted text -

- Show quoted text -


copy/paste of the function with no modifications. I think Clif may be
on to something about it being a different instance of excel...
reccomendations?


The ref to 'Application' in the function is the current instance of
Excel in which the code is running. The function won't work on other
instances running at the same time. Not sure why this would be an issue
since most users use the same instance of Excel for all open workbooks.
In order for me to have multiple instances open at the same time it
would be a deliberate action on my part to do so. (Not withstanding
automated instances)

--
Garry

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