• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

Use Variables/Parameters to pass Methods or Properties in COM w/AutoHotkey

I had wanted to be able to make a function where I pass Methods or Properties in COM.  (this makes it much more flexible and eases updating / maintaining of code.)  Unfortunately it was not as straight-forward as I’d hoped.

Thankfully maestrith, Author of AutoHotkey Studio, had already solved this problem and shared the solution with me!  The code which shows how to pass Methods or Properties in COM is listed below.  While in the video I demonstrate connecting to IE and perform web scraping, the solution is equally applicable to any COM object like Excel, etc.

pwb := WBGet()


ID_Var:= PXL.document.GetElementByID(ID)
MsgBox % ID_Var[Property]
;~  MsgBox % pwb.document.GetElementByID("site-description").OuterHTML
;~  MsgBox % pwb.document.GetElementByID("site-description").InnerHTML


pwb := WBGet()
MsgBox % WebScraping_Get(pwb,"class","widget_tag_cloud","0","")
MsgBox % WebScraping_Get(pwb,"id","tag_cloud-3",,"oh")

;***********Getting data from page*******************
;***********Set Methods and Properties to static so do not have to rebuild each time it is called*******************
static Methods:={id:"getElementByID",class:"getElementsByClassName",tag:"getElementsByTagName",name:"GetElementsByName"}
static Properties:={it:"InnerTEXT",ot:"OuterText",ih:"InnerHTML",oh:"OuterHTML",vl:"Value",si:"selectedIndex",ck:"checked"}
Doc:= PXL.document
if (method !="id")
      return Doc[Methods[Method]](Thing)[Index][Properties[Property]] ;Arrays
      return Doc[Methods[Method]](Thing)[Properties[Property]] ;Not an Array

Demonstration Video to pass Methods or Properties in COM