Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Basic Ahk_L COM Tutorial for Excel

  • Please log in to reply
227 replies to this topic
  • Members
  • 5 posts
  • Last active: Oct 05 2015 12:24 PM
  • Joined: 22 Sep 2015

Hi Guys, first Hello to AHK community. I am totally new with AHK but found it very powerful and want to get some things done.


First Q - I am running my first script to open an excel file and my intention is to run personal macro into it via Send ^K (CTRL + K). My issue is that after the file get opened there are no available personal macros at all. When I open the file w/o a script it work fine.


Tried to search for the solution via web but maybe you can pass me with a quick answer.


Second Q - how to repeat it for several files in the same script?


ps. I've found out that here I should present only working script. Lets park it for the time being I'll receive some advice.


Here is the sample of the code which open excel file.


Excel: 2010

OS: Win7

AHK: latest one

xlFile := A_ScriptDir "\file.xls"
try xl := ComObjActive("Excel.Application")
	xl := ComObjCreate("Excel.Application")
Book := xl.WorkBooks.Open(xlFile)
xl.Visible := True

  • Members
  • 6 posts
  • Last active: Sep 28 2015 09:14 PM
  • Joined: 11 Sep 2015

Xl := ComObjActive("Excel.Application") ; create Excel Application object
Xl.Visible := 1 ; make Excel Application visible
Xl.Sheets("Forecast1").Select  ; this works to activate the script


After I run this script and close excel, Excel is still active in the task manager?  Any idea what causes this?

  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

You have made Excel visible with Xl.Visible := 1. So even if your script has exited you should be able to close Excel as usual.


If your script did not make Excel visible you will need to end the process from the Task Manager. Ideally in this case your script should have quit excel, but if the script has already closed or you didn't write that into the script that is not an option.


Perhaps you tried some scripts previously that did not make Excel visible, and that is the instance of Excel you are seeing in the Task Manager?