Consulting

Results 1 to 4 of 4

Thread: VBA to set Azure label

  1. #1
    VBAX Regular
    Joined
    Sep 2020
    Posts
    51
    Location

    VBA to set Azure label

    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

  2. #2
    VBAX Regular
    Joined
    Sep 2020
    Posts
    51
    Location
    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.

  3. #3
    VBAX Expert
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    697
    Location
    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
    Last edited by Aussiebear; 05-10-2022 at 11:06 PM. Reason: An Aussie teaching an Englishman how to spell
    If things don't change they stay the same
    Quite often there is a picnic problem (problem in chair not in computer)
    "We were not told it was impossible, so we did it."

  4. #4
    VBAX Regular
    Joined
    Sep 2020
    Posts
    51
    Location
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •