Page 1 of 1

Code Optimization: Call rejected errors

Posted: 08 Dec 2021, 06:47
by jc0r
Hi all,

Can anyone suggest a better way of running the below code maybe without the use of a loop as i intermittenly get "Call was rejected by callee" errors on row := used.Rows(A_Index) & If (row.Cells(12).Text != "TRUE"). I'm not editing anything in Excel although i do have a 3rd party program displaying its data on a sheet via COM. Ive tried inserting sleeps, even ridiculous long sleeps of 10000 and they still appear. When the code works as expected it only take around 3 seconds to execute the maximum number of send commands to Book.exe and the CalcMyArr macro only takes around 3 milliseconds to execute.

Code: Select all

#Persistent
XL := ComObjActive("Excel.application"), used := XL.Sheets(2).UsedRange

SetTimer, Check, 10000
Check:
XL.Run("CalcMyArr")
Sleep, 1000
Loop, % used.Rows.Count 
{
 row := used.Rows(A_Index)
 If (row.Cells(12).Text != "TRUE")
  Continue
 WinActivate, ahk_exe Book.exe
 WinWaitActive, ahk_exe Book.exe
 Send, % row.Cells(14).Text "`n" row.Cells(13).Text
}
Return

Re: Code Optimization: Call rejected errors

Posted: 08 Dec 2021, 10:56
by just me
IMO, VBA indices are 0-based. So valid row indices would be 0 thru used.Rows.Count - 1 (i.e.A_Index - 1).

Re: Code Optimization: Call rejected errors

Posted: 08 Dec 2021, 11:32
by flyingDman
I cannot replicate the error. It works fine here. Although I would have used a For loop, a regular loop is fine. It's not an issue with index. used.Rows(1).cells(1).text shows me the content of the top left cell. used.Rows(0).cells(1).text gives me an error (as expected). Have you tried Excel_Get() ?. Search for it on the forum.