 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Mon Mar 08, 2010 4:06 pm Post subject: Activate one of mutiple Excel windows |
|
|
Hello friends,
I am a freshman in AHK. There is something make me confuse, I am always activate a Excel window by the script as blow:
| Code: |
WinWait, Microsoft Excel - a.xls,
IfWinNotActive, Microsoft Excel - a.xls, , WinActivate, Microsoft Excel - a.xls,
WinWaitActive, Microsoft Excel - a.xls,
|
but in our daily work. we always need to open mutiple Excel windows. like "a.xls", "b.xls", "c.xls", "d.xls"......recently I found if "a.xls" is the first Excel window to be opened, then "a.xls" can not be activated by the scipt as above.(example: first, I open "a.xls", and then I open "b.xls" or creat a new Excel file "book1.xls". after that I run the scrift as above. window "Microsoft Excel - a.xls" can not be activated)
Could anyone help? Thanks a lot!!! |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Tue Mar 09, 2010 5:41 pm Post subject: |
|
|
| Leef_me wrote: | You don't provide the version of excel you are using, could you provide that?
|
My excel has a little lagged behind, just 2003
I think the problem may due to the same MDI interface. I tried to delete "Microsoft Excel - ", just run as "WinActivate, a.xls". it works. but not stably. error are always happened. so...I am trying to find another way...[/img] |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Tue Mar 09, 2010 9:55 pm Post subject: |
|
|
| Jinan wrote: | | so...I am trying to find another way...[/img] |
Read the last thread listed in my prior post.
I also have EXCEL 2002 installed on another machine
This script works for me with the file names a.xls b.xls and c.xls
There is one caveat, all 3 files must be opened in the same instance of Excel.
To illustrate: If I open excel and drag/drop the 3 files onto the excel window, it works fine.
If I select thm in one Windows Explorer window and hit enter, this script will work.
If I open each of the files from the Excel File->Open menu, it will work.
What will not work: is to open one or two of the files, then open excel again (using a
desktop shortcut, or Start->Programs...) and then try to open the remaining excel file(s)
| Code: | settitlematchmode 2
F1::
winactivate a.xls
return
F2::
winactivate b.xls
return
F3::
winactivate c.xls
return
|
|
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Wed Mar 10, 2010 3:59 pm Post subject: |
|
|
| Leef_me wrote: |
I also have EXCEL 2002 installed on another machine
|
I think 2002 and 2003 should be the same...
Thank you for your reminder, "SetTitleMatchMode" is usefully.
I could activate the window via the script. But I also wanna add some text into the Excel. Could you try the blow script?
| Code: |
^g::
settitlematchmode 2
;SetDefaultMouseSpeed, 0
WinWait, a.xls,
IfWinNotActive, a.xls, , WinActivate, a.xls,
WinWaitActive, Microsoft Excel - a.xls,
;click, 63,18
sendinput, zzzzzz
send, {Tab}
return
|
You must try to run this script more than 10 times(Run on other actived Excel windows), and then you will find the problem(s). Sometimes the window looks like activated, actually not. but it still keeps running. So made some error. ("SetDefaultMouseSpeed, 0" and "click, 63,18" look like a little stupid, But I have to make sure the script Sendinput ZZZZZZ after the window have been activated.)
Are there any solutions for that? Thanks a lot |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Wed Mar 10, 2010 8:21 pm Post subject: |
|
|
I've noticed a different response between XL2002 and XL2007 to a few things I have tried.
I haven't been able to make much sense of the results.
I do need to ask, are you planning to have the A.xls b.xls etc maximized withing the parent Excel frame or are you planning them to be non-maximized?
The reason I ask is that the title of the Excel window changes based on whether the the active spreadsheet is maximized or not.
If the spreadsheet is maximized (_not_ necessasarily the excel window) then the title of the window is a combination of "Microsoft Excel" and the title of the spreadsheet. (The word arrangement is different between versions)
Anyway, if the spreadsheet is maximized within the Excel frame, then all the old methods seem to work.
| Code: |
WinWait, a.xls,
IfWinNotActive, a.xls, , WinActivate, a.xls,
WinWaitActive, a.xls,
|
If the spreadsheet is not maximized, then the a.xls is in the title of its _own_ window.
With the result that "WinWaitActive" doesn't /see/ it
I suggest looking at the remarks of
http://www.autohotkey.com/docs/commands/WinMaximize.htm
Try the Postmessage command shown there by trying "a.xls" in each of the WinTitle, WinText parameters
(remember to make the unsed parameter empty)
that's all I have for now. I think I need to go lie down, this is weird. |
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Thu Mar 11, 2010 4:55 pm Post subject: |
|
|
| Leef_me wrote: |
that's all I have for now. I think I need to go lie down, this is weird. |
yes...much weirdly
Anyway, thank you. I will try "WinMaxmize". I think it is a good way for solving the problem. my boss pushed me everyday.... |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Thu Mar 11, 2010 5:22 pm Post subject: |
|
|
I may be off base here, but it sounds like there is an issue activating an Excel window where there are multiple WorkBooks open for one Excel Object/Process ( check the Window HWND/ID ). If you have Excel open, go to the Start menu & click Microsoft Excel, it will create a new Excel object/process. ( this can be confusing since each workbook has its own tab on the taskbar; if you just double click on an xls file, it will open it in a pre-existing excel object/process if one exists ). If you have two or more WorkBooks open in the same Excel object/process & need to activate an unactive one, you can use the following code ( written for AHKL & COM_L ): | Code: | WorkBookName := "c.xls"
pxl := COM_GetActiveObject( "Excel.Application" ) ; the next 2 lines are more reliable
; ControlGet, handle, hwnd, , EXCEL71, <WinTitle>
; pxl := COM_AccessibleObjectFromWindow(handle,-16).Application
pxl.WorkBooks( WorkBookName ).Activate
WinActivate, <WinTitle> |
NOTE - for multiple workbooks in the same excel object/process, the only WinTitle that exists is Microsoft Excel - <Active WorkBook>; ie - only the active workbook exists as a window, not the other workbooks (even though they have a tab in the taskbar ) . _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Sun Mar 14, 2010 3:34 pm Post subject: |
|
|
| jethrow wrote: | | you can use the following code ( written for AHKL & COM_L ): |
Hello jethrow,
Thanks for helping me out, You are very talented. I think COM is a better way for that. but I don't know it well. when I run blow script. A warning pop up ------ The following variable name contains an illegal character: ".Activate".
| Code: | ^f::
WorkBookName:= "a.xls"
pxl:= COM_GetActiveObject("Excel.Application")
pxl.WorkBooks(WorkBookName).Activate
WinActivate, Microsoft Excel - a.xls
return |
Is there some additional module need to be installed into my computer? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Sun Mar 14, 2010 6:40 pm Post subject: |
|
|
AHKL is a separate build of AHK that supports objects. You will notice there is also two different versions of the COM Standard Library. To use the code I provided, you need to use AHKL & COM_L. Otherwise, here is the same code written for the standard release of AHK & COM: | Code: | ^f::
WorkBookName:= "a.xls"
COM_Init()
pxl := COM_GetActiveObject( "Excel.Application" )
oWorkBook := COM_Invoke( pxl, "WorkBooks", WorkBookName )
COM_Invoke( oWorkBook, "Activate" )
COM_Release( pxl ), COM_Release( oWorkBook ), COM_Term()
WinActivate, Microsoft Excel - a.xls
return |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Jinan
Joined: 08 Mar 2010 Posts: 11
|
Posted: Mon Mar 15, 2010 4:43 pm Post subject: |
|
|
| jethrow wrote: | | AHKL is a separate build of AHK that supports objects. You will notice there is also two different versions of the COM Standard Library |
It worked and it became more stable. It fixed the problem perfectly. Thank you!
But i still have three more questions:
1. Where could I get the details of each function?
2. How could I get some information for learning COM? I think I really need these.
3. I need to create an ".EXE" file and use in three computers. Do I need to put the whole script of COM.ahk into my program? (If I want to run the program on share drive and I could not create any file on their computers.) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|