Call was rejected by callee pulling from Excel Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Call was rejected by callee pulling from Excel

Post by morreo » 08 Dec 2022, 11:11

Hello,

I'm quite the novice, so my code might look not great. About 3 out of 4 times, I will get an error "Call was rejected by Callee. Specifically: Value" when I try to pull data from a cell in excel. On the 4th try, it will probably work as expected.

I know the reason it isn't working is because the excel is doing hundreds of other things while my script tries to pull data from the excel, but I can't find a working solution to have it keep trying.

Here is a snippet my code:

Code: Select all

F6::
wbk := ComObjGet("C:\Users\Trader\Desktop\StellarApplications\spreadsheets\FED FUNDS POSITIONSZ3NBareDashboardStellarMonitoringUpDown.xlsm")
while (-not wbk.Ready) {
     sleep 1
}
A1Val := wbk.Sheets("Sheet1").Cells(1, 1).Value ;This is where the issue is
A1Val := Round(A1Val)
Sleep, 50
Return
I TRIED a workaround with the Try/catch but I'm not sure if I used it correctly? I've never used a try/catch before. This code essentially does nothing:

Code: Select all

F6::
wbk := ComObjGet("C:\Users\Trader\Desktop\StellarApplications\spreadsheets\FED FUNDS POSITIONSStellarSR3MonitoringUpDown.xlsm")
while (-not wbk.Ready) {
     sleep 1
}
Sleep, 10
	loop
	{
	try (A1Val := wbk.Sheets("Sheet1").Cells(14, 14).Value, error:=0) ;I'm pretty confident I didn't write this correctly because the script does nothing once it gets here
	catch error
	sleep 10
	if (!error)
	break
	}
Sleep, 10
	loop
A1Val := Round(A1Val)
Return
Any thoughts or maybe slight editing for the 2nd code that I posted? I know i'm close but I just can't get it.

Thanks!!!

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Call was rejected by callee pulling from Excel

Post by boiler » 08 Dec 2022, 13:48

The - in while (-not wbk.Ready) is likely only causing the while loop not to actually wait until it's ready. It's probably causing that loop to not loop at all regardless of the actual value of the ready state. Why is it there?


See if this script waits until you press the A key before displaying the MsgBox:

Code: Select all

while (-not GetKeyState("a", "P"))
	Sleep, 50
MsgBox, done

Then try this version:

Code: Select all

while (not GetKeyState("a", "P"))
	Sleep, 50
MsgBox, done

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Call was rejected by callee pulling from Excel

Post by flyingDman » 08 Dec 2022, 14:41

I do not believe there is any circumstance requiring you to use a while ... sleep. Try deleting it and see what happens. For some reason, working with COM rarely requires inclusion of "sleeps".

On another note, although ComObjGet works, I much prefer using xl := ComObjActive("excel.application") or xl := ComObjCreate("excel.application") although it adds a few lines to my script. The reason is that there is a hierarchy that i like to respect app→workbook→sheet→range→cell and there seems to be always a need - in larger / more complex scripts - to come back to the app level. You can use wbk.parent, but that seems to go against the grain.
The Error: 0x80010001 - Call was rejected by callee. error is often due to the fact that the excel file is in edit mode. This can be prevented by using excel_get(). See here: https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
14.3 & 1.3.7

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Call was rejected by callee pulling from Excel  Topic is solved

Post by morreo » 08 Dec 2022, 15:16

You guys gave me a fresh set of eyes and I found out I was running a infinite loop (not sure why I put loop twice in the original code). I also found out that I did not need the While ... sleep as you guys mentioned so I took that out and it seemed fine.

I will work on
xl := ComObjActive("excel.application")
notation so that it's built more stable.

This code works!

Code: Select all

F6::
wbk := ComObjGet("C:\Users\Trader\Desktop\StellarApplications\spreadsheets\FED FUNDS POSITIONSStellarSR3MonitoringUpDown.xlsm")
Sleep, 10
	loop
	{
	try (A1Val := wbk.Sheets("Sheet1").Cells(14, 14).Value, error:=0)
	catch error
	sleep 10
	if (!error)
	break
	}
Sleep, 10
A1Val := Round(A1Val)
return

Post Reply

Return to “Ask for Help (v1)”