Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Created December 16, 2019 03:25
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/a70617b73bb8961361730785505aa6be to your computer and use it in GitHub Desktop.
Save TLMcode/a70617b73bb8961361730785505aa6be to your computer and use it in GitHub Desktop.
Detect Data in Excel Cells per Row using ComObjectConnect
wbk := ComExcelConnect( "ahk_class XLMAIN" ).Application ; ComObjActive("Excel.Application")
; a::
F1::
; Loop % UsedRows
While ( A_Index <= wbk.ActiveSheet.UsedRange.Rows.Count )
{
CurRow := A_Index, Cols := wbk.Cells( CurRow, 256 ).End( -4159 ).Column
Loop % Cols
{
if ( wbk.Cells( CurRow, A_Index ).Value != "" )
{
CellObj := wbk.Cells( CurRow, A_Index )
; place action here!
; remove below msgbox for display purposes only!
msgbox % "Cell: " CellObj.Address( 0, 0 ) "`nValue: " CellObj.Value
}
}
}
return
ComExcelConnect( WinTitle )
{
DetectHiddenWindows, On
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