Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default activating windows

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default activating windows

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 at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default activating windows

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.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default activating windows

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 at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default activating windows

"GS" wrote in message
...
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?



Different instances of Excel, maybe?

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default activating windows

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?
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default activating windows

There may be an easier workaround... This workbook will ALWAYS have
one sheet in it named rwservlet. Is there a way to activate just that
sheet without having to reference the workbook it is in, since that
name is subject to change?
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default activating windows

Matthew Dyer used his keyboard to write :
There may be an easier workaround... This workbook will ALWAYS have
one sheet in it named rwservlet. Is there a way to activate just that
sheet without having to reference the workbook it is in, since that
name is subject to change?


No! You must always use fully qualified refs.

You may be able to set an object variable to that sheet when it's the
active sheet at some point prior.

Example:
In the declarations section of a standard module:
Dim wksServlet As Worksheet

In some procedure that opens the workbook containing this sheet:
Set WksServlet = ActiveSheet

To ref it later on:
WksServlet.Activate

OR
just act directly on the sheet without activating it at all:
WksServlet.Range("A1").Value = 123

--
Garry

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple windows of single file display on windows taskbar easylife Excel Programming 2 June 3rd 09 03:29 PM
cannot open exel from windows xp in windows vista and visa versa lildiana New Users to Excel 4 February 25th 09 07:26 PM
can not save spreadsheet from a windows service on windows server dragonemp Excel Programming 2 November 3rd 08 03:48 PM
can windows vista edit shared document from windows xp sasa Excel Worksheet Functions 1 January 9th 08 06:44 PM
Activating/De-activating buttons Nash Excel Programming 4 June 22nd 05 07:24 AM


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"