Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Created August 4, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TLMcode/cf8cf82f71b9333ed3a9 to your computer and use it in GitHub Desktop.
Save TLMcode/cf8cf82f71b9333ed3a9 to your computer and use it in GitHub Desktop.
ComExcelConnect() creates a COM connection to a open workbook
xlObj := ComExcelConnect( "ahk_class XLMAIN" ).Application
msgbox % xlObj.Range("A1").value
ExitApp
ComExcelConnect( WinTitle )
{
objID := "-16", objID &= 0xFFFFFFFF
refID := -VarSetCapacity( iid, 16 )
iid_type := NumPut( 0x46000000000000C0
, NumPut( 0x20400, iid, "Int64" )
, "Int64")
ControlGet, hwnd, hwnd, , EXCEL71, % WinTitle
DllCall( "oleacc\AccessibleObjectFromWindow", ptr, hwnd, uInt, objID, ptr, refID+iid_type, "ptr*", pObj )
return ComObjEnwrap( 9, pObj )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment