Are AHK COM functions not available in Outlook anymore?
-
- Posts: 61
- Joined: 25 Jan 2016, 14:26
Are AHK COM functions not available in Outlook anymore?
My understanding from https://stackoverflow.com/questions/76364711/new-outlook-design-2023-comobjactiveoutlook-application-not-working-anymore is that COM objects are no longer supported in the "new" Outlook. I’ve tried several simple legacy AHK-Outlook functions that always generate an error in AHK at the beginning stage, i.e., Outlook := ComObjActive("Outlook.Application"). The error is 0x800401E3 - Operation unavailable.
But I wanted to ask here because I have been able to automate several things in Outlook in python using the win32com.client library, which I understand also accesses the COM object model. Any help would be appreciated!
But I wanted to ask here because I have been able to automate several things in Outlook in python using the win32com.client library, which I understand also accesses the COM object model. Any help would be appreciated!
Re: Are AHK COM functions not available in Outlook anymore?
COM won't work in the new Outlook. Good news is that, from what I can tell, new Outlook will not replace Outlook. It's similar to other email programs in the past and present; like if you remember Outlook Express.
This is a quote from the best summary I've seen:
Other links:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/one-outlook
https://duckduckgo.com/?t=ffab&q=new+outlook+vba+alternative&ia=web
I haven't tried automating the new Outlook. Maybe things like chrome.ahk or UIA would be the way to go since it's a web application.
This is a quote from the best summary I've seen:
-The new Outlook, much confusion, VBA, developer tools, accounts wrote:[New Outlook] is not a successor, but a completely different application.
...
many functions are missing. For example, the developer tools are completely missing. Macros in VBA do not work.
...
the old Outlook will continue to exist in Microsoft Office.
Other links:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/one-outlook
https://duckduckgo.com/?t=ffab&q=new+outlook+vba+alternative&ia=web
I haven't tried automating the new Outlook. Maybe things like chrome.ahk or UIA would be the way to go since it's a web application.
-
- Posts: 61
- Joined: 25 Jan 2016, 14:26
Re: Are AHK COM functions not available in Outlook anymore?
Thank you for your reply @Datapoint! I was mistaken as to what the "new Outlook." I guess I’m still trying to automate the "old Outlook," i.e., the desktop office 365 application. An example of code that produces the error is this:
Code: Select all
#y::
app := ComObjActive("Outlook.Application")
olAppointmentItem := 1 ;1 is the olItemType Enumeration for Appointment
olMeeting := 1 ; olMeeting is an appointment so initialize to 1 here also.
MailItem := app.CreateItem(olAppointmentItem)
MailItem.MeetingStatus := olMeeting
MailItem.Subject := "mysubject"
MailItem.Recipients.Add("firstemail@gmail.com")
MailItem.Recipients.Add("secondemail@gmail.com")
MailItem.Location := "mylocation"
MailItem.Display
return
Re: Are AHK COM functions not available in Outlook anymore?
- My first guess is that Outlook is running as admin. If Outlook is running as admin then the script would need to be admin also. It's better if both are not running as admin.
- ComObjActive needs Outlook to be running. If it's not running then use ComObjCreate instead.
- If you just launched Outlook, you need to wait a bit and/or switch to another window before Outlook registers itself to be visible to ComObjActive.
- You could try the GetActiveObjects function. The following should display "Outlook" if it is found:
Code: Select all
for name, obj in GetActiveObjects() try MsgBox % obj.Name
-
- Posts: 61
- Joined: 25 Jan 2016, 14:26
Re: Are AHK COM functions not available in Outlook anymore?
Strange, I tried your code and it didn’t notify me of any active COM objects, not even in Microsoft Word or Excel. I tried running my AHK script as administrator and that didn’t do the trick either.
For what it’s worth, the following code does work to run a macro I’ve defined in Microsoft Word. Why it works is beyond my coding knowledge.
For what it’s worth, the following code does work to run a macro I’ve defined in Microsoft Word. Why it works is beyond my coding knowledge.
Code: Select all
1:: RunMSWordMacro("ShrinkFont")
RunMSWordMacro(name) {
GetWord().Run(name)
}
GetWord() {
if !hwnd := WinActive("ahk_class OpusApp")
hwnd := WinExist("ahk_class OpusApp")
ControlGet, ControlHwnd, Hwnd,, _WwG1, ahk_id %hwnd%
Return AccObjectFromWindow(ControlHwnd, -16).Application
}
AccObjectFromWindow(hWnd, idObject = 0)
{
static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}"
, IID_IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}"
, OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, h := DllCall("LoadLibrary", Str, "oleacc", Ptr)
VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
DllCall("ole32\CLSIDFromString", Str, idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, Ptr, &IID)
if DllCall("oleacc\AccessibleObjectFromWindow", Ptr, hWnd, UInt, idObject, Ptr, &IID, PtrP, pAcc) = 0
Return ComObjEnwrap(VT_DISPATCH, pAcc, 1)
}
Re: Are AHK COM functions not available in Outlook anymore?
It sounds like you are having the same issue as @burque505 mentioned in this thread. The underlying cause of the issue was not found in the other thread. You came to the same solution of using AccessibleObjectFromWindow as a workaround.
They use different methods to retrieve the object. ComObjActive("Outlook.Application") uses the registry to find the object. (HKEY_CLASSES_ROOT\Outlook.Application\CLSID) Whereas AccessibleObjectFromWindow, as the name suggests, just gets the object from the window.poetofpiano wrote: Why it works is beyond my coding knowledge.
The script I posted would only show objects that have a .name property. The first example on the GetActiveObjects page will show all the available COM objects. On my system, Outlook is !{0006F03A-0000-0000-C000-000000000046} -- _Application and that matches the CLSID in the registry.poetofpiano wrote: Strange, I tried your code and it didn’t notify me of any active COM objects, not even in Microsoft Word or Excel.
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: Are AHK COM functions not available in Outlook anymore?
Code: Select all
for each, obj in GetActiveObjects() ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6494
try MsgBox % obj.Name
If you're running Microsoft 365, go to My Account on Microsoft's website and check that the PC you are running this on is one of the Devices that are registered (in the Devices section and the Install Microsoft 365 section). If not that might be your issue.
14.3 & 1.3.7
-
- Posts: 61
- Joined: 25 Jan 2016, 14:26
Re: Are AHK COM functions not available in Outlook anymore?
I see. Is it possible to write a version that allows COM automation in Outlook? (I found the GetWord() function online and don’t understand how it works. I tried replacing ahk_class OpusApp with ahk_class rctrl_renwnd32 but of course that didn’t work, haha.