Anyone having issues retrieving Excel com obj?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Anyone having issues retrieving Excel com obj?

08 Jan 2018, 10:29

Hi,

I've been on win 10 for about six months and was pleased that all my scripts were working. Over the past week I noticed that ComObjActive("Excel.Application") is not returning anything or generates an error "Error: 0x800401e3 "Operation unavailable". I have the same issue on office 2010 and office 2016. I'm using AHK v1.1.26.01 64-bit.

I have experimented with timing and with a microsoft support article that says focus must be removed from Excel momentarily once it starts to trigger it registering with the OP system. I placed the "ComObjActive" statement in a loop and it just gets stuck there.

Any ideas?

Relayer
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: Anyone having issues retrieving Excel com obj?

08 Jan 2018, 10:49

Some more tinkering shows that the same construct works fine in Word 2016. Excel remains recalcitrant!

Relayer
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: Anyone having issues retrieving Excel com obj?

29 Jan 2018, 09:27

This is solved. I thought I would post the resolution just in case it might save someone the frustration of dealing with windows.

Problem recap: Upgrade to windows 10 from 7 caused my AHK script that augments Excel to not function... "operation unavailable" when trying to connect to com.

Source of problem: mismatch between "run as administrator" setting with respect to AutoHotkey or Excel keeps the connection at bay. As soon as I turned that off on Excel, everything began to function as it did before the upgrade to win 10.

Relayer
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Anyone having issues retrieving Excel com obj?

29 Jan 2018, 14:08

Relayer wrote:Source of problem: mismatch between "run as administrator" setting with respect to AutoHotkey or Excel keeps the connection at bay. As soon as I turned that off on Excel, everything began to function as it did before the upgrade to win 10.
I have experienced the same things. When you google the problem you get all kinds of information about the Excel object not registering and ways to force it to register.

But what you don't find as easily is information about it being a permission problem that is not allowing AHK to access the Excel object, which is what the problem has always been for me.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Anyone having issues retrieving Excel com obj?

15 Mar 2018, 10:12

Hi, I'm having a different but related issue. I run Win7 64-bit, Office 2016 64-bit. I experienced the "Error: 0x800401e3 'Operation unavailable'" for weeks when I ran any script that has "ComObjActive()" using a 64-bit AHK (including Excel, which this thread is really about). However, if I switched to a 32-bit Unicode AHK, everything worked fine. GetActiveObjects() didn't show a single active object with 64-bit, but did with 32-bit. Tried with 1.1.126.01, 1.1.27.07.

Bizarrely, it seems to me, I just switched to V2 and ran a couple of suitably modified scripts, in which ComObjActive() worked fine with 64-bit.
And then when I switched back to V1, 64-bit AHK runs the ComObjActive() scripts. GetActiveObjects() also retrieves them.

(Outlook 2016 64-bit, the only one installed, is giving me problems, though. It doesn't show up in the ROT at all, which is certainly not an AHK problem, but it does mean I can't automate it. This sounds to me like a weird enough issue that I'm likely the only person having it, but if anyone else is experiencing anything similar, please let me know. I know this is straying off-topic. I'm trying Office Repair to see if that helps.

Thanks!

Regards,
burque505
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Anyone having issues retrieving Excel com obj?

15 Mar 2018, 12:04

burque505 wrote:(Outlook 2016 64-bit, the only one installed, is giving me problems, though. It doesn't show up in the ROT at all, which is certainly not an AHK problem, but it does mean I can't automate it. This sounds to me like a weird enough issue that I'm likely the only person having it, but if anyone else is experiencing anything similar, please let me know. I know this is straying off-topic. I'm trying Office Repair to see if that helps.
You might try Excel_Get function at:
https://autohotkey.com/boards/viewtopic.php?t=31840

It goes about things a different way by first finding the Excel window and then working from there to get the object associated with the window.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Anyone having issues retrieving Excel com obj?

15 Mar 2018, 15:07

Excel_Get.ahk
(1.48 KiB) Downloaded 111 times
Thanks, FG, I have fallen back on Excel_Get in the past when ComObjActive fails. I think I got this attached version from jeeswg on March 4 or thereabouts. It doesn't need Acc (probably the same version modified by kon that is referenced in your link, since that apparently doesn't need Acc).
I believe I've discovered the root of my main problem, though. I have AHK set to run as Admin, and that is causing problems.

If I execute a batch file like so:

Code: Select all

AutoHotkeyU64.exe MyComObjScript.ahk
using a copy of the executable that isn't set to run elevated, then my ComObjActive problems go away. GetActiveComObjs() sees everything when run that way also. (Strangely (to me anyway) when I run a ROTviewer program as admin, none of the Com objects show up either.)

So, as was pointed out earlier, permission problems seem to be at the heart of these ComObjActive issues, one way or another.

I have noticed also that if there's a ComObjCreate executed earlier in a script, ComObjActive doesn't fail, at least for that created object.

Regards,
burque505
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Anyone having issues retrieving Excel com obj?

15 Mar 2018, 16:18

burque505 wrote:I believe I've discovered the root of my main problem, though. I have AHK set to run as Admin, and that is causing problems.
That is an important point, you can't just run as admin and all your permission problems will be solved. It is more about a mismatch of permissions than having "high enough" permission. Admin can create as many problems as it solves. In alot of ways running as Admin tells Windows to watch this program very carefully because it wants permission to do dangerous stuff.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: Anyone having issues retrieving Excel com obj?

03 Apr 2018, 09:37

I have always been bewildered by Microsoft's approach to security. I just cannot develop a mental model that works. I think most people struggle with it and just try things until it seems to work. I have summed up my thoughts in the following quotable: "Microsoft's approach to the computer interface is orthogonal to my experience as a human being".

Relayer
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Anyone having issues retrieving Excel com obj?

03 Apr 2018, 10:03

That reminds me of something somebody at GM said about Microsoft once, after a derogatory comment by Bill Gates. I'm paraphrasing, but it went something like this:
"If cars were designed by Microsoft, you'd have to stop them with the start button." I'm sure the story has metastasized over the years - here's one link that has comments in a similar vein.
Regards,
burque505
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

Re: Anyone having issues retrieving Excel com obj?

04 Apr 2018, 08:55

I have the same problem with Photoshop. ComObjActive("Photoshop.Application") works fine when I have just one version of Photoshop installed, but when I install a second version on the same computer (a more recent version, for example), then I get the "Operation Unavailable" error, even though only one of the two versions is running at any given time. If I un-install one of the two versions, the error continues. I need to totally remove BOTH versions from the system, reboot, re-install only ONE version, and then it works again. So needless to say I'm, afraid to update Photoshop now because Adobe leaves the previous version installed, while adding the newer version to your computer - hence having two versions installed.

Is there a way to work around this?
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: Anyone having issues retrieving Excel com obj?

04 Apr 2018, 11:06

:wave: scriptor2016

You might be able to specify the version number. I don't have Photoshop. This is for Excel:
app := ComObjCreate("{00024500-0000-0000-C000-000000000046}")
or app := ComObjCreate("Excel.Application.14")

Look in the registry at HKEY_CLASSES_ROOT\Photoshop.Application\CLSID
or HKEY_CLASSES_ROOT\Photoshop.Application.XX ("XX" is a version number)

Then maybe use try/catch to try to get the application and if it fails your script can try a different version.
User avatar
FanaticGuru
Posts: 1905
Joined: 30 Sep 2013, 22:25

Re: Anyone having issues retrieving Excel com obj?

04 Apr 2018, 12:45

scriptor2016 wrote:I have the same problem with Photoshop. ComObjActive("Photoshop.Application") works fine when I have just one version of Photoshop installed, but when I install a second version on the same computer (a more recent version, for example), then I get the "Operation Unavailable" error, even though only one of the two versions is running at any given time. If I un-install one of the two versions, the error continues. I need to totally remove BOTH versions from the system, reboot, re-install only ONE version, and then it works again. So needless to say I'm, afraid to update Photoshop now because Adobe leaves the previous version installed, while adding the newer version to your computer - hence having two versions installed.

Is there a way to work around this?
awel20 advice is very good. It is important to realize that the Photoshop.Application is just kind of like a user-friendly alias to a CLSID. These 'aliases' are defined in the Registry which probably gets deleted when you full uninstall. The actual CLSID can be used to be more precise which version of an application you are trying to access. No two different applications every created are ever supposed to have the same CLSID. These are supposed to be total unique IDs. Randomly generated with astronomical odds of every producing two the exact same.

For example (but I would not recommend it), you could even do something like create a registry entry like "PS_COM" that had the proper CLSID property. Then you could do app := ComObjCreate("PS_COM").

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

Re: Anyone having issues retrieving Excel com obj?

07 Apr 2018, 02:02

Ha! It worked! You guys are awesome :)

I've been having this problem for years now, and have even inquired about it in the past but I thought it was too rare a problem for anyone to actually know what the problem was.

I can now have several versions of Photoshop installed and can use the version number to isolate the particular version which is actively running. So awesome.

Thanks guys
User avatar
Chunjee
Posts: 1397
Joined: 18 Apr 2014, 19:05
Contact:

Re: Anyone having issues retrieving Excel com obj?

16 Nov 2018, 11:35

Relayer wrote:
29 Jan 2018, 09:27
Source of problem: mismatch between "run as administrator" setting with respect to AutoHotkey or Excel keeps the connection at bay. As soon as I turned that off on Excel, everything began to function as it did before the upgrade to win 10.
How do you "turned that off on Excel"? I'm on a new computer with Win10 and Office365 and having similar symptoms.

Relayer
ttttt
Posts: 9
Joined: 01 Jun 2017, 03:59

Re: Anyone having issues retrieving Excel com obj?

27 May 2019, 03:42

FanaticGuru wrote:
04 Apr 2018, 12:45
For example (but I would not recommend it), you could even do something like create a registry entry like "PS_COM" that had the proper CLSID property. Then you could do app := ComObjCreate("PS_COM").
Sorry for digging up an old thread, but I wonder how would I do that? I have the same issue with multiple Photoshops, and I want to run a script in CC2018. But there's no Photoshop.Application for CC2018 in registry, can I manually add a CLSID? If yes, where can I find the actual ID? Thank you!
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

Re: Anyone having issues retrieving Excel com obj?

27 May 2019, 08:49

ttttt wrote:
27 May 2019, 03:42
FanaticGuru wrote:
04 Apr 2018, 12:45
For example (but I would not recommend it), you could even do something like create a registry entry like "PS_COM" that had the proper CLSID property. Then you could do app := ComObjCreate("PS_COM").
Sorry for digging up an old thread, but I wonder how would I do that? I have the same issue with multiple Photoshops, and I want to run a script in CC2018. But there's no Photoshop.Application for CC2018 in registry, can I manually add a CLSID? If yes, where can I find the actual ID? Thank you!
On my system, I have CC2014, CC2018 and CC2019 installed.

For CC2014, the entry in the registry is Photoshop.Application.80

For CC2018, it's Photoshop.Application.120

For CC2019, it's Photoshop.Application.130

These values are found at HKEY_CLASSES_ROOT\Photoshop.Application.XX (where "XX" is the version number)

So for example, there are many values in the registry on my system. My registry looks something like this:

Photoshop.Application.120
Photoshop.Application.120.1 ...(I think the .1 represents an update to CC2018- for example, CC2018.1 sort of thing)
Photoshop.Application.130
Photoshop.Application.130.1 ...(same as above)
Photoshop.Application.80
Photoshop.Application.80.1 ...(same as above)



I don't know if these values will be the same on your system, but just check them out and you will find them there. Then, just trial-and-error it until you get the right ones. That's how I figured out which which value corresponded to which version of Photoshop.


So for CC2014, my line of code looks like:

Code: Select all

appRef := ComObjActive("Photoshop.Application.80")
ttttt
Posts: 9
Joined: 01 Jun 2017, 03:59

Re: Anyone having issues retrieving Excel com obj?

06 Jun 2019, 03:13

scriptor2016 wrote:
27 May 2019, 08:49
So for CC2014, my line of code looks like:

Code: Select all

appRef := ComObjActive("Photoshop.Application.80")
Thank you for your reply. This is super weird, I also have all these Applications in registry. If I have CC2019 running and do
appRef := ComObjActive("Photoshop.Application")
or
appRef := ComObjActive("Photoshop.Application.130")

appRef is defined and my code works fine.

But when I have CC2018 running,
appRef := ComObjActive("Photoshop.Application")
gives me an error (I tried to wrap it in rty..catch, but the error seems to be empty)

And
appRef := ComObjActive("Photoshop.Application.120")
simply does nothing. My code doesn't work and when I try to MsgBox, %appRef%, I'm getting an empty message box
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

Re: Anyone having issues retrieving Excel com obj?

06 Jun 2019, 08:52

I hadn't tried that before. When I try

Code: Select all

Msgbox, %appRef%
I also get a blank messagebox.

But rest assured, my code still works no matter which version of Photoshop I'm using.
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

Re: Anyone having issues retrieving Excel com obj?

06 Jun 2019, 08:57

ttttt wrote:
06 Jun 2019, 03:13
simply does nothing. My code doesn't work and when I try to MsgBox, %appRef%, I'm getting an empty message box
scriptor2016 wrote: I hadn't tried that before. When I try

Code: Select all

Msgbox, %appRef%
I also get a blank messagebox.
appRef contains an object. MsgBox will always be blank. If you want something to display in the MsgBox then you need to access a member of the object that returns text .
Msgbox, % IsObject(appRef)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Greg_Roberts, inseption86, narej, Rohwedder and 187 guests