ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN
if !(Xl := Acc_ObjectFromWindow(hwnd, -16).Application) {
Msgbox, 262144, @(>_<)@, No active Excel sheet.
ExitApp
}
loop
row := A_Index
until (xl.range("a" . A_Index).value = "")
f2::
Try xl.range("a" . row).value := "testing"
Catch
Xl := Xl_Conn() ; returns zilch
return
Xl_Conn() {
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN
if !(Xl := Acc_ObjectFromWindow(hwnd, -16).Application)
Msgbox, 262144, @(>_<)@, No active Excel sheet.`n`nOpen a spreadsheet and try again.
else return Xl
}
Acc_ObjectFromWindow(hWnd, IdObject = -4) {
static h
if not h
h := DllCall("LoadLibrary","Str","oleacc","Ptr")
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", IdObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID, 16)+NumPut(IdObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81, NumPut(IdObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID, "Int64"), "Int64"), "Ptr*", pacc)=0
return ComObjEnwrap(9, pacc)
}It should attempt the first empty cell to "testing" otherwise call the function that relinks the workbook. I tested this by using the hotkey on an open workbook, closing the workbook, hitting hotkey again which causes the error message, then I open the workbook again, and use the hotkey. The msgbox does not trigger but the workbooks cell isn't set. In the error log I just see the Try trigger but it skips the Catch. What's up?Hope I'm not wasting anyones time. :oops:




