Control via COM an already open Excel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jekko

Control via COM an already open Excel

22 Feb 2018, 11:46

Hello, i have this issue

Code: Select all

oExcel := ComObjCreate("Excel.Application") 
oExcel.Workbooks.Add 
oExcel.Visible := 1
With these lines of code i can open a new Excel instance and control it via the COM.
BUT
if an excel application is ALREADY open (with an active sheet), how could assign that istance to a COM object in order to control it via AHK?

Thank you for the replies
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Control via COM an already open Excel

22 Feb 2018, 19:11

Try this:
Excel_Get - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Control via COM an already open Excel

22 Feb 2018, 23:36

You can also try just using the command made for it:
xlApp := ComObjActive("Excel.Application")

This will work for most people. It is all I ever use and I use COM with Excel alot on several different computers.

The Excel_Get function is more robust and can handle some fringe cases.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Jekko

Re: Control via COM an already open Excel

23 Feb 2018, 03:47

Thank you very much.

ComObjActive for now is enough for me, if i will detect further problems i will pass to Excel_Get()

Jekko

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Dobbythenerd1 and 326 guests