AutoHotkey Community

It is currently May 26th, 2012, 11:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: November 9th, 2009, 6:26 pm 
Offline

Joined: November 9th, 2009, 6:19 pm
Posts: 8
Hi,

I currently have code that will run a macro on a specific workbook, so long as this workbook has been opened first. The problem is, that I sometimes will have another workbook that was opened first, and thus I get an error stating the macro cannot be found.

I need a method of access a specific workbook by title name to run macros. My current code:

Code:
COM_CoInitialize()

oExcel := COM_GetActiveObject("Excel.Application")

oWorkbook := COM_Invoke(oExcel, "application.run(getAHKPremiums)")

oWorkbook := COM_Invoke(oExcel, "application.run(getAHKClaimLines)")

COM_Release(oWorkbook)
COM_Release(oExcel)


I've been searching in vain for over an hour now, and I'll continue searching in the meantime.

Thanks in advance for any help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 6:35 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I would recommend using Sean's GetExcel()function:
Code:
oExcel := GetExcel(hwnd)


Or, if you know the full workbook path & name:
Code:
oWorkBook := COM_GetObject("path + name")

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:11 pm 
Offline

Joined: November 9th, 2009, 6:19 pm
Posts: 8
Thanks Jethrow!

The second method (GetObject) seemed to have worked just fine.

As for the GetExcel(hwnd), I'm not sure how I am supposed to use this function. I looked it up based on the link you provided, but I couldn't find an example where a unique identifier would have been entered.

I have tried various combinations for hwnd, but to no avail.

Your patience are appreciated ;)

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:17 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Actually, Sean uses it in the function:
Code:
WinGet, hWnd, ID, Window Title

oExcel := GetExcel(hWnd)

Or, you should be able to use WinExist()as well.

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on November 9th, 2009, 7:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:37 pm 
Offline

Joined: November 9th, 2009, 6:19 pm
Posts: 8
I'll try that out.

Thanks a bunch!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 7:50 pm 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Or, you could do this:
Code:
ControlGet, hwnd, hwnd, , EXCEL71, Window Title
oWorkBook := COM_AccessibleObjectFromWindow(hwnd,-16)

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 9th, 2009, 11:48 pm 
Offline

Joined: November 9th, 2009, 6:19 pm
Posts: 8
Got it to work with the GetExcel function along with WinGet.

Thanks man.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, Leef_me, Pulover, rbrtryn, XstatyK and 23 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:
cron
Powered by phpBB® Forum Software © phpBB Group