it seems you can set a workbook’s Azure Information Protection Sensitivity label using this method:
https://www.mrexcel.com/board/excel-articles/change-sensitivity-label-programatically.66/
Function SetSensitivityLabel(WB As Workbook, LblName As String)
Dim myLabelInfo As Office.LabelInfo
Dim Context As Variant
Dim objWorkbook As Workbook
Dim CurLabelID As String
Dim sPublic As String
Dim sGeneral As String
Set objWorkbook = ActiveWorkbook
Set myLabelInfo = objWorkbook.SensitivityLabel.CreateLabelInfo()
Set Context = CreateObject("Scripting.Dictionary")
sPublic = "788c8a80-3a15-4016-b4c2-fc99999bfa99"
sGeneral = ""
Select Case LblName
Case "General"
CurLabelID = sGeneral
Case "Public"
CurLabelID = sPublic
End Select
With myLabelInfo
.AssignmentMethod = MsoAssignmentMethod.PRIVILEGED '1
.ContentBits = 4
.IsEnabled = True
.Justification = "Because" 'Make this whatever you want
.LabelId = CurLabelID
.LabelName = LblName
.SetDate = Now()
End With
objWorkbook.SensitivityLabel.SetLabel myLabelInfo, Context
End Function
However, I’d like to do this for an Outlook MailItem created via VBA – not a workbook. Changing objWorkbook
to an Outlook MailItem
in the Function above doesn’t expose SensitivityLabel.CreateLabelInfo()
. Is there any other way to do this? Looking at this other thread (Azure classification using vba), some answers use a draft template, some use SendKeys – both are suboptimal and answers quite old.
Is there any equivalent for Outlook that doesn’t employ these methods?