VBA Error _ Add Sensitivity label

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
979
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

While saving a workbook via vba , I am getting one pop up message
Add Sensitivity label ,
how to disable this message.

via vba please help. thanks in advance !



I am getting erorr at at below line
nwbk.SaveAs Filename:=newFilePath, FileFormat:=xlOpenXMLWorkbook

VBA Code:
Sub test()
   Dim Cl As Range
   
   
   newFilePath = "D:\output\test.xlsx"
   
   Dim nwbk As Workbook
   Set nwbk = Workbooks.Add
   
   Dim ws As Worksheet
   Set ws = nwbk.ActiveSheet
   
   ws.Range("a1").Value = "Hi"
   
   
    
    Application.DisplayAlerts = False
    On Error Resume Next
    nwbk.SaveAs Filename:=newFilePath, FileFormat:=xlOpenXMLWorkbook  'pop up message
    
    Application.DisplayAlerts = True
    
    
End Sub



Thanks
mg
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello @Mallesh23.
Your error does not reproduce for me. The file is created and saved in the specified directory with the specified name without a single error or message. The code is working.
 
Upvote 0
@Mallesh23 see the article below if your company has set sensitivity labels (but easier to talk to your IT Dept. about it as they should have explained it)

 
Last edited:
Upvote 0
Hi Mark,

I tried above code , still it is asking me
add Sensitivity label while saving a workbook.




thanks
mg
 
Upvote 0
Can you not just set the sensitivity label for the document manually from your Home tab or your Windows bar?
 
Upvote 0
I tried that , set to Internal -General Use

But everytime macro runs new workbook is created with time stamp attached to it

I get pop up message Add sensitity label

select a label , with below dropdown


Internal - General Use
Public
Personal - Individual Use
Confidential


also cancel option is there

plz help how to disable or select confidential or cancel it. I am using office 365


Thanks
mg
 
Upvote 0
plz help how to disable or select confidential or cancel it. I am using office 365
It is a security measure set by your company, we do advise (even if we could) on how to disable, cancel or get around security measures on this forum.

You can try saving the workbook manually after setting the label

then run the code below

VBA Code:
Sub getlabel()
    Dim myLabelInfo As Office.LabelInfo
    Dim labelpart1 As String, labelpart2 As String

    Set wb = ThisWorkbook

    Set myLabelInfo = wb.SensitivityLabel.getlabel()

    labelpart1 = myLabelInfo.LabelId
    labelpart2 = myLabelInfo.SiteId

    With Sheets("Sheet1")                        ' change Sheet1 to an empty sheet

        .Range("A1").Value = labelpart1 ' Label ID
        .Range("A2").Value = labelpart2 ' Site ID

    End With


End Sub

Then use the information it gives you as per the below followed by your save line on the other files

VBA Code:
Dim docSenseLabel As SensitivityLabel
Dim labelInfo As Office.labelInfo

Set docSenseLabel = wb.SensitivityLabel
Set labelInfo = docSenseLabel.CreateLabelInfo()

With labelInfo
    .AssignmentMethod = MsoAssignmentMethod.PRIVILEGED
    .LabelId = "the labelId you got"
    .LabelName = "Important"   'or whatever label you saved earlier
    .SiteId = "the site Id you got"
End With

docSenseLabel.setlabel labelInfo, labelInfo

Please note that the code above isn't mine and I am not on a work computer to test it
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,457
Members
452,515
Latest member
nguyenkim

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