Excel Error 0x800401e3

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jakobsendk
Posts: 15
Joined: 07 Dec 2018, 16:08

Excel Error 0x800401e3

09 Dec 2018, 12:06

Hi

I have the following code, but when i gets to Xl := ComObjActive("Excel.Application") I just get the error 0x800401e3.

If I open excel and then run the script it all work just fine. Is there a workaround so my application is not dependent excel is running?

Code: Select all

FileDir := "C:\" ; specify the full path of the folder here
FilePath := FileDir . "\" . A_YYYY . A_MM . A_DD . ".xlsx"
Run, EXCEL.EXE "%FilePath%"
Sleep, 3000

Xl := ComObjActive("Excel.Application") 
Xl.Range("A:T").Copy ;copy cell to clipboard
Thanks for your help
gregster
Posts: 8990
Joined: 30 Sep 2013, 06:48

Re: Excel Error 0x800401e3

09 Dec 2018, 14:22

The sleep might not be sufficient (try longer sleeps). Check for the existence of the Excel window via WinWait (and then add perhaps some sleep anyway).
Is there a reason why you don't create the Excel instance via ComObjCreate ?

Also this might be relevant: https://support.microsoft.com/en-us/hel ... pplication
[...]
When an Office application starts, it does not immediately register its running objects. This optimizes the application's startup process. Instead of registering at startup, an Office application registers its running objects in the ROT once it loses focus. Therefore, if you attempt to use GetObject or GetActiveObject to attach to a running instance of an Office application before the application has lost focus, you might receive one of the errors above.

Resolution

Using code, you can change focus from the Office application to your own application (or to some other application) to allow it to register itself in the ROT. Additionally, if your code is launching the Office application's exe file, you might need to wait for the Office application to finish loading before attempting to attach to the running instance.[...]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 237 guests