Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel App 1

Status
Not open for further replies.

Sridharan

Technical User
Dec 3, 2001
523
IN
Hello All,

Suppose I have two excel windows with separate workbooks. How to activate the other excel window from the active excel thru a macro.

Thanks In Advance
Sri
 
How about using ...

ActiveWindow.ActivateNext

in your macro.

Cheers, Glenn.
 
Hi Glenn,

Thanks for your response.

I tried that but it doesn't show the other Excel Window.
I hope you got my question!

Thanks
Sri
 
My method will work if the 2 workbooks are open in the same Excel instance ( multiple workbooks can be opened in the same Excel instance, and can be navigated via the Window menu command ).

The method will not work if the workbooks have been opened in different Excel instances.

Glenn.
 
Hi Glenn,

Yeah it shows the other excel book. But my requirement is to show the other Excel Application Window altogether. Any ideas????

Thanks

Sri
 
Just a quick question before I think about this ... why have you got the 2 workbooks in different instances of Excel?

Glenn.
 
Hi Glenn,

Thanks again for your response.

One of the user wants to copy something from the current excel window workbook to a new workbook already open in the other excel window.

I did showed this but he insists on something like that for reasons well known to him.

Any ideas how to get this done.

Thanks
Sri
 
Yup - slap the user and tell them not to open seperate instances of excel..... ;-) Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Absolutely Geoff,

a good slapping goes a long way with awkward users.

Tell the user that the advantages of having different windows in the same Excel instance far FAR outweigh any possible reason he can have ( to have different instances ), that to not do so would be stupid.

If he still insists on having different instances of Excel, ask him why, 'cos I'd like to hear it.

Glenn.
 
Glenn,

I would love to but can't. The reasons couldn't get it.

Sri
 
Well, in that case you are probably going to need an API call - have alook here to see if there is anything that brings a window to the front:

However, I dunno if there will be a way of finding out which program is in which window (you will need this if you need to go to excel specifically)

I really would guard against this kind of thing tho. There is no, I repeat, no reason for the user to be working in 2 instances of excel Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
If you really, really need to do this, and if you know the name of the worksheet to be activated then you can try using the Windows API calls like this:
Code:
Option Explicit

Const SW_NORMAL As Long = 1
Const SW_MINIMIZE As Long = 6
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function ShowWindowAsync& Lib "user32" _
   (ByVal hwnd As Long, ByVal nCmdShow As Long)

Sub ActivateOtherWorkbook(WorkbookName As String)
Dim hw&
  hw& = FindWindow(vbNullString, "Microsoft Excel - " & WorkbookName)
  If hw& = 0 Then
    hw& = FindWindow(vbNullString, "Microsoft Excel")
  End If
  ShowWindowAsync hw&, SW_MINIMIZE
  ShowWindowAsync hw&, SW_NORMAL
End Sub

Sub test()
  ActivateOtherWorkbook ("New Text Document.txt")
End Sub
 
Zathras,

Thanks for your code! It worked. Many a Thanks. But is it possible to bring the other excel window which might come if we use ALt+Tab without giving the workbook name.

That would be something great and would be much obliged.

Thanks
Sri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top