Using AHK and Excel's COM

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Using AHK and Excel's COM

22 Oct 2018, 16:02

Hi folks,

I've been dinging around with COM in Excel for the last couple of weeks and the more I learn, the more complex and difficult each problem I am trying to solve becomes.

I've looked at countless forum posts on COM in Excel, many with varying techniques to do essentially the same thing.

Seems like using the Excel_Get() method over using Xl := ComObjActive("Excel.Application") is the more robust way to go, but I don't understand how to use this method. I've been able to do some cool, yet basic stuff with the Xl := ComObjActive method already. But I'm looking to start copying data between two Excel files and between a web browser and an Excel file and I'm getting really confused on how to do that. The context behind this is that I am building out the automation of the creation of monthly reports for enterprise-level businesses.

Can someone help me out or direct me to the best way to learn how to use the Excel_Get method?

I come across many posts that are from sometimes over 10 years ago, I'm looking for the most up-to-date documentation/tutorials on this.

Also, how does one translate VBA code to Autohotkey? I see the similiarities, but too new to AHK to understand how I can write AHK code from VBA. I've seen a translator, but more interested in how to do it myself?

Thanks a bunch in advance! :beer:
-TL
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Using AHK and Excel's COM

22 Oct 2018, 18:57

Tigerlily wrote:
22 Oct 2018, 16:02
Hi folks,

I've been dinging around with COM in Excel for the last couple of weeks and the more I learn, the more complex and difficult each problem I am trying to solve becomes.

I've looked at countless forum posts on COM in Excel, many with varying techniques to do essentially the same thing.

Seems like using the Excel_Get() method over using Xl := ComObjActive("Excel.Application") is the more robust way to go, but I don't understand how to use this method. I've been able to do some cool, yet basic stuff with the Xl := ComObjActive method already. But I'm looking to start copying data between two Excel files and between a web browser and an Excel file and I'm getting really confused on how to do that. The context behind this is that I am building out the automation of the creation of monthly reports for enterprise-level businesses.

Can someone help me out or direct me to the best way to learn how to use the Excel_Get method?

I come across many posts that are from sometimes over 10 years ago, I'm looking for the most up-to-date documentation/tutorials on this.

Also, how does one translate VBA code to Autohotkey? I see the similiarities, but too new to AHK to understand how I can write AHK code from VBA. I've seen a translator, but more interested in how to do it myself?

Thanks a bunch in advance! :beer:
There is not much to know about using Excel_Get.

Code: Select all

xlApp := ComObjActive("Excel.Application")
; Basically the same
xlApp := Excel_Get()
Excel_Get is just a user function that checks for a few things that may cause errors and helps handle if there are more than one copy of Excel running. Most of the time the additional features it provides are not needed.
https://autohotkey.com/boards/viewtopic.php?t=31840

As far as updated information, this is pretty good:
https://autohotkey.com/boards/viewtopic.php?t=8978
Especially the part 6 which is a bunch of links to other sources.

The important thing about going from VBA to AHK is to realize that it is not so much translating as they are both accessing the same underlying COM object. COM is built into Windows. Both VBA and AHK are accessing this COM. VBA and AHK are different languages so the commands and syntaxes are different but the COM object they are accessing is the same as it exist separate from both languages.

This is a link to the Microsoft documentation on the Excel application object:
https://docs.microsoft.com/en-us/office ... on(object)

From here you can see all the methods and properties of the Excel application object. It is a giant branching tree where each property is often another object with its own methods and properties which in turn has its own methods and properties. There are many hundreds of methods and properties going many layers deep.

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 214 guests