I have a macro that creates and saves multiple word and excel documents. Recently, My organisation started using Microsoft Azure protection. It always asks the user to choos
It seems that after more than a year there is still no solution. At least I did not find any native VBA integration for AIP.
However I found a solution for myself. Basically I create now a draft of a mail manually where I choose the classification manually. This draft remains in a special folder in outlook. Once I need to send a mail via VBA I copy the draft (classification included!), I change recipients, object, body and I am able to send it without user interaction from VBA since the classification is already done.
Private Sub Email()
Dim oMailItem As Outlook.MailItem
'Set oMailItem = Outlook.Application.CreateItem(olMailItem)
'Choose template according to subject
'I have one template for each sensitivity classification
Set oMailItem = getVbaTemplateMail("VBA Template - Sensitivity=General")
With oMailItem
.To = "mail@a.b"
.subject = "Email Test using VBA"
.Body = "Test"
.Display
.Send
End With
Set oMailItem = Nothing
End Sub
Private Function getVbaTemplateMail(subject As String) As Outlook.MailItem
Dim olFolder As Outlook.MAPIFolder
Dim olItem As Outlook.MailItem
'GetDefaultFolder(16) = Draft folder, "Drafts/VBA Templates" is my VBA Template folder
Set olFolder = Application.GetNamespace("MAPI").GetDefaultFolder(16).Folders("VBA Templates")
For Each olItem In olFolder.Items
Debug.Print olItem.subject ' Print to immediate window
If olItem.subject = subject Then
Set getVbaTemplateMail = olItem.Copy
'If error "Active Inline Response" appears, the mail is open in Outlook, close it first!
Exit Function
End If
Next
End Function