0

enter image description here

On outlook application I created a new folder with name “Template”.
Inside that folder, I manually put some emails, with inside it my excel macro workbooks.
Macro settings on Excel are Disable all macros with notification,
as a result when I open any macro workbook, I got a security warning that macros have been disabled,
and I need to click Enable Content each time.

enter image description here

I could not find any way to add these files to a trusted location or even make as trusted document.
So, as a work around, I need to change excel macro settings (temporarily) from outlook when opening any email on that folder “Template” to Enable all macros and after close this email or sent it, then revert macro settings again to “Disable all macros with notification”.
Note 1, Sure, I mean change these macro settings @ my machine only and not at the recipient PC.
Note 2, I already using some macros globally inside outlook (auto zoom), and signed these macros by creating a Digital Signature using SelfCert.exe، therefore I do not get any security warning when using that macros.
Note 3, I found this question Link, But I could not adapt the provided answer to my needs ,and I use office 2016 32Bit on windows 10 64Bit.
In advance grateful for useful comments and answer.

Public WithEvents myItem As Outlook.MailItem
Public EventsDisable as Boolean

Private Sub Application_ItemLoad(ByVal Item As Object)
    If EventsDisable = True Then Exit Sub
    If Item.Class = olMail Then
        Set myItem = Item
    End If
End Sub

Private Sub myItem_Open(Cancel As Boolean)
    EventsDisable=True
   'Your code
    EventsDisable=False
End Sub
Leedo
  • 439
  • 5
  • 18

1 Answers1

-1

You'd be better off creating a VSTO COM addin in VB.Net - it will be able to work without prompts.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I don't think you'd be able to do much unless you enable the macros. – Dmitry Streblechenko Mar 27 '22 at 05:55
  • But, there are already running macro inside `ThisOutlookSession` and this macro is signed by a (personal digital certificate) therefore I do not get any security warning.If there is not any hope with VBA solution ,kindly could you help with creating `VSTO COM addin in VB.Net` – Leedo Mar 27 '22 at 06:07
  • You can start at https://learn.microsoft.com/en-us/visualstudio/vsto/create-vsto-add-ins-for-office-by-using-visual-studio?view=vs-2022 – Dmitry Streblechenko Mar 27 '22 at 16:40
  • Please, If I opened an email ,Is it possible to get the name of it's folder (Inbox,sent,...) using vba? – Leedo Mar 27 '22 at 16:53
  • 1
    Sure, `MailItem.Parent` will give you the parent folder. `MailItem.Parent.Name` will give you the name of the parent folder. – Dmitry Streblechenko Mar 27 '22 at 17:46