| View previous topic :: View next topic |
| Author |
Message |
searle
Joined: 09 Nov 2009 Posts: 8
|
Posted: Mon Nov 09, 2009 5:26 pm Post subject: Excel Macro Activation (Two Workbooks) |
|
|
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. |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 722 Location: Iowa, USA
|
Posted: Mon Nov 09, 2009 5:35 pm Post subject: |
|
|
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") |
_________________ AHKL, COM_L,Webpage Controls,Donate to AHK |
|
| Back to top |
|
 |
searle
Joined: 09 Nov 2009 Posts: 8
|
Posted: Mon Nov 09, 2009 6:11 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 722 Location: Iowa, USA
|
Posted: Mon Nov 09, 2009 6:17 pm Post subject: |
|
|
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. _________________ AHKL, COM_L,Webpage Controls,Donate to AHK
Last edited by jethrow on Mon Nov 09, 2009 6:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
searle
Joined: 09 Nov 2009 Posts: 8
|
Posted: Mon Nov 09, 2009 6:37 pm Post subject: |
|
|
I'll try that out.
Thanks a bunch! |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 722 Location: Iowa, USA
|
Posted: Mon Nov 09, 2009 6:50 pm Post subject: |
|
|
Or, you could do this: | Code: | ControlGet, hwnd, hwnd, , EXCEL71, Window Title
oWorkBook := COM_AccessibleObjectFromWindow(hwnd,-16) |
_________________ AHKL, COM_L,Webpage Controls,Donate to AHK |
|
| Back to top |
|
 |
searle
Joined: 09 Nov 2009 Posts: 8
|
Posted: Mon Nov 09, 2009 10:48 pm Post subject: |
|
|
Got it to work with the GetExcel function along with WinGet.
Thanks man. |
|
| Back to top |
|
 |
|