PDA

View Full Version : [SOLVED:] VBA to set Azure label



twmills
05-10-2022, 08:46 AM
When creating a new excel file - and saving them to a shared drive - an Azure Information Protection Classify and Protect box appears asking to label the file as either Public Information, Internal Information, Confidential Information or Personal Information.

I have a macro that creates a bunch of different files, but when they are created and saved an Azure classification doesn't get applied to them. If it was just one file then I can easily just manually add the classification no problem. However, when the macro creates a dozen or so files, then having to classify each one, one at a time, take a little more time.

Is there a way - through vba - to set the Azure classification to "Confidential Information" as the excel file is saved to the shared drive?

I tried recording myself doing it manually, but vba doesn't pick it up.

Thanks as always

twmills
05-10-2022, 11:04 AM
Nevermind...not worth anyone's time to look into. Solved my own problem here.

Just found out you can select all the files you want (while holding down shift or ctrl), and after right clicking you can apply the Azure tag manually all at once. Takes only a few seconds to do.

Hopefully no one wasted any time on this.

Thanks.

georgiboy
05-10-2022, 10:59 PM
Your post got me thinking (and googling), as what if you were to save hundreds of files in different locations?
Anyway i am not running 365 and nor do i have the Azure security but i found and modified the below but have been unable to test.
Maybe if you ever have the need you could play with something like the below (untested):


Sub set_label() Dim label_info As Office.LabelInfo
Dim wb As Workbook

Set wb = Workbooks.Add
Set label_info = wb.SensitivityLabel.CreateLabelInfo
With label_info
.ActionId = "" 'fill
.AssignmentMethod = MsoAssignmentMethod.PRIVILEGED 'fill
.ContentBits = 0 'fill
.IsEnabled = True
.Justification = "" 'fill
.LabelId = "" 'fill
.LabelName = "" 'fill
.SetDate = Now()
.SiteId = "" 'fill
End With
wb.SensitivityLabel.SetLabel label_info
wb.SaveAs Environ("USERPROFILE") & "\Desktop\wb with label.xlsx"
wb.Close True
End Sub

twmills
05-11-2022, 05:05 AM
Yes, I think I came across this same code while researching it. If the manual process ever becomes too much, I'll look into automating it using this code.

I appreciate it!