AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excel Macro Activation (Two Workbooks)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
searle



Joined: 09 Nov 2009
Posts: 8

PostPosted: Mon Nov 09, 2009 5:26 pm    Post subject: Excel Macro Activation (Two Workbooks) Reply with quote

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
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 722
Location: Iowa, USA

PostPosted: Mon Nov 09, 2009 5:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
searle



Joined: 09 Nov 2009
Posts: 8

PostPosted: Mon Nov 09, 2009 6:11 pm    Post subject: Reply with quote

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 Wink

Thanks.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 722
Location: Iowa, USA

PostPosted: Mon Nov 09, 2009 6:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
searle



Joined: 09 Nov 2009
Posts: 8

PostPosted: Mon Nov 09, 2009 6:37 pm    Post subject: Reply with quote

I'll try that out.

Thanks a bunch!
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 722
Location: Iowa, USA

PostPosted: Mon Nov 09, 2009 6:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
searle



Joined: 09 Nov 2009
Posts: 8

PostPosted: Mon Nov 09, 2009 10:48 pm    Post subject: Reply with quote

Got it to work with the GetExcel function along with WinGet.

Thanks man.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group