Reputation: 20899
We have a small macro (added to the ribbon) which on click is supposed to attach some files from a certain folder.
This works, when creating a "new" Mail from within Outlook. When you use (for example) Adobe Acrobats "send as email" Function, the email in Outlook is opened as modal dialog.
The button on the ribbon now has no effect. It simple does nothing. (Not even a MessageBox in the first line would be displayed) Using Developer Tools -> Macros and selecting the macro from "there" works.
Why isn't the button on the ribbon, calling the very same macro NOT working with modal emails?
the macro - but as mentioned not even a MessageBox would appear.
Sub AddAttachments()
Dim Path As String
Path = "C:\test\"
Dim NewMail As MailItem, oInspector As Inspector
Set oInspector = Application.ActiveInspector
If oInspector Is Nothing Then
MsgBox "No active inspector"
Else
Set NewMail = oInspector.CurrentItem
If NewMail.Sent Then
MsgBox "This is not an editable email"
Else
With NewMail
d = Dir(Path & "*.*")
While d <> ""
.Attachments.Add Path & d
d = Dir
Wend
End With
End If
End If
End Sub
Update: With another application offering more settings for the email-sending application, I was able to figure the following out:
So, Adobe Acrobat seems to use (Simple) MAPI by default.
Edit: After knowing the actual cause, I found this: https://www.msoutlook.info/question/203 - Seems to be a known, not solvable limitation for Applications creating their emails through MAPI because Outlook is not loaded "fully" but just some basic stub.
Update:
When clicking on the "Send as mail Button" (1) the following Window appears. Clicking on the "Macro-Button" inside the ribbon (2) does nothing.
Switching to DeveloperTools, Selecting "Macros" and selecting the same Macro from there however works:
The Button on the other hand works for "New Emails" created via Outlook and "New Mails" created by using Outlook OLE
rathen than MAPI
.
Upvotes: 2
Views: 831
Reputation: 20899
Okay, to summarize the problem and the missing solution:
I was in touch with the support of various applications showing this problem and they confirmed, that this problem is caused by using MAPI
as entrypoint.
For Example, "PDF24" allows you to specify wheter it should use MAPI
or Outlook OLE
: Choosing MAPI
results in the same problem, while choosing Outlook OLE
makes VBA-Macros work...
I also noted, that the Addin responsible for processing VBA-Scripts
(Microsoft.VbaAddinForOutlook
) is not loaded, when Outlook is triggered using MAPI
:
The Eventlog (Application) shows that several Addins are loaded during startup:
Outlook loaded the following add-in(s):
Name: Microsoft Exchange Add-in
Description: Exchange support for Unified Messaging, e-mail permission rules, and calendar availability.
ProgID: UmOutlookAddin.FormRegionAddin
GUID: {F959DBBB-3867-41F2-8E5F-3B8BEFAA81B3}
Load Behavior: 3
HKLM: 1
Location: C:\Program Files (x86)\Microsoft Office\Root\Office16\ADDINS\UmOutlookAddin.dll
Boot Time (Milliseconds): 0
Name: Outlook Social Connector 2016
Description: Connects to social networking sites and provides people, activity, and status information.
ProgID: OscAddin.Connect
GUID: {2163EB1F-3FD9-4212-A41F-81D1F933597F}
Load Behavior: 3
HKLM: 1
Location: C:\Program Files (x86)\Microsoft Office\Root\Office16\SOCIALCONNECTOR.DLL
Boot Time (Milliseconds): 0
...
But the VBA-Addin is only loaded, when "clicking" on the macro-button for the first time, because it's LoadBehavior: 9
rather than LoadBehavior: 3
:
(This event appears "onclick"):
Name: Microsoft VBA for Outlook Addin
Description:
ProgID: Microsoft.VbaAddinForOutlook.1
GUID: {799ED9EA-FB5E-11D1-B7D6-00C04FC2AAE2}
Load Behavior: 9
HKLM: 1
Location: C:\Program Files (x86)\Microsoft Office\Root\Office16\ADDINS\OUTLVBA.DLL
Boot Time (Milliseconds): 0
(The event is completly missing, when the Window is created through a MAPI-Call
)
I managed to "fake" a Entry in the Registry in order to load the Addin right away:
[HCU\SOFTWARE\Microsoft\Office\Outlook\Addins\Microsoft.VbaAddinForOutlook.1]
"LoadBehavior"=dword:00000003
Which indeed made the Addin load during Outlook-Startup - but without the desired impact of having VB-Macros working in MAPI
-generated Email-Windows.
Name: Microsoft VBA for Outlook Addin
Description:
ProgID: Microsoft.VbaAddinForOutlook.1
GUID: {799ED9EA-FB5E-11D1-B7D6-00C04FC2AAE2}
Load Behavior: 3
HKLM: 1
Location: C:\Program Files (x86)\Microsoft Office\Root\Office16\ADDINS\OUTLVBA.DLL
Boot Time (Milliseconds): 0
But maybe "this" might be a good starting point for somebody facing the same Problem and seeking for a solution.
Upvotes: 1