AutoHotkey Community

It is currently May 27th, 2012, 5:39 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: March 8th, 2010, 5:06 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 5:02 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
You don't provide the version of excel you are using, could you provide that?

All of the commands you list are based on how you match the title.
The spelling, punctuation and even LeTtEr CaSe matter.
http://www.autohotkey.com/docs/commands/WinWait.htm
http://www.autohotkey.com/docs/commands ... chMode.htm

If the files are in the same MDI interface you might need to try this thread.
http://www.autohotkey.com/forum/viewtopic.php?t=55080


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 6:41 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2010, 10:55 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2010, 4:59 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2010, 9:21 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
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/ 8) 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 :arrow: 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 5:55 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2010, 6:22 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
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 ) .

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 4:34 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 7:40 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
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

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2010, 5:43 pm 
Offline

Joined: March 8th, 2010, 3:55 pm
Posts: 11
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! :D
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.)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], HotkeyStick, mrhobbeys and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group