VBA to set Sensitivity Label

adilsabirazeez

New Member
Joined
Mar 13, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am generating a set of excel files into a folder. I want to set the sensitivity label of all these files to a particular category like "Highly Confidential". I am not able to find VBA to automate this.

If anyone has any solution, then please post it.

Thanks in advance.
 
Hi,

I am generating a set of excel files into a folder. I want to set the sensitivity label of all these files to a particular category like "Highly Confidential". I am not able to find VBA to automate this.

If anyone has any solution, then please post it.

Thanks in advance.


I looked everywhere and could not find a straight forward answer. I got this working from info from all over the place and it should work for everyone. Drop these in a worksheet, make sure there is a sheet1. Use the get label info to get the info from the currently set label on YOUR sheet. Update the setLabelInfo subs with your own label information. Then you can use them to set/switch the sensitivity label as needed. I tried to keep these as simple as possible so you can modify as needed or copy the parts needed into your code.

VBA Code:
Sub SetLabelInfoINTERNAL()
     Dim myLabelInfo As LabelInfo
     Set wb = ThisWorkbook
     Set myLabelInfo = wb.SensitivityLabel.CreateLabelInfo()
     
     With myLabelInfo
     'put your information here ***********************
      .ActionId = "c0f18baa-5255-463b-8176-67e75ee5abc4"
      .AssignmentMethod = MsoAssignmentMethod.PRIVILEGED
      .ContentBits = 2
      .IsEnabled = True
      .Justification = "Some justification needed only if downgrading label."
      .LabelId = "eae83a4f-cc5f-4276-a1aa-251cec914c6b"
      .LabelName = "Internal"
      .SetDate = Now()
      .SiteId = "d554a4b7-b1f6-4714-a568-fd4d48c146a6"
     End With
    
    Call wb.SensitivityLabel.setLabel(myLabelInfo, myLabelInfo)

End Sub


Sub SetLabelInfoEXTERNAL()
     Dim myLabelInfo As LabelInfo
     Set wb = ThisWorkbook
     Set myLabelInfo = wb.SensitivityLabel.CreateLabelInfo()
     
     With myLabelInfo
     'Put Your information here ***********************
      .ActionId = "e00c1536-0827-5aca-8e56-ef075b47683a"
      .AssignmentMethod = MsoAssignmentMethod.PRIVILEGED
      .ContentBits = 2
      .IsEnabled = True
      .Justification = "Some justification needed only if downgrading label."
      .LabelId = "97be529e-63ab-4d1a-985e-0328b4465a07"
      .LabelName = "External"
      .SetDate = Now()
      .SiteId = "d584a8b7-b1f2-7714-a278-fd4d83c145a6"
     End With
    
    Call wb.SensitivityLabel.setLabel(myLabelInfo, myLabelInfo)

End Sub

Sub getLabelInfo()

    Dim senLabelInfo As Office.LabelInfo
    
    Set wb = ThisWorkbook
    Set senLabelInfo = wb.SensitivityLabel.GetLabel()
    Call wb.Sheets("Sheet1").Activate
    
    property1 = senLabelInfo.LabelName
    property2 = senLabelInfo.LabelId
    property3 = senLabelInfo.SiteId
    property4 = senLabelInfo.SetDate
    property5 = senLabelInfo.ActionId
    property6 = senLabelInfo.Application
    property7 = senLabelInfo.AssignmentMethod
    property8 = senLabelInfo.ContentBits
    property9 = senLabelInfo.Creator
    property10 = senLabelInfo.IsEnabled
    property11 = senLabelInfo.Justification
    
    Range("A1").Value = "Label Name"
    Range("B1").Value = property1
    Range("A2").Value = "Lablel ID"
    Range("B2").Value = property2
    Range("A3").Value = "Site ID"
    Range("B3").Value = property3
    Range("A4").Value = "Set Date"
    Range("B4").Value = property4
    Range("A5").Value = "ActionId"
    Range("B5").Value = property5
    Range("A6").Value = "Application"
    Range("B6").Value = property6
    Range("A7").Value = "AssignmentMethod"
    Range("B7").Value = property7
    Range("A8").Value = "ContentBits"
    Range("B8").Value = property8
    Range("A9").Value = "Creator"
    Range("B9").Value = property9
    Range("A10").Value = "IsEnabled"
    Range("B10").Value = property10
    Range("A11").Value = "Justification"
    Range("B11").Value = property11

End Sub
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top