Method 'SetLabel' of Object 'ISensitivityLabel" failed in Visio VBA

Didier 5 Reputation points

Hello .

I have written a VBA script from a MS Visio file.

In this script, I am creating an excel file from a Visio Report, and need to assign a sensitivity label (as requirement by my company) before saving it.

I use the code below.

It works fine when I use debug / step by step mode.

But when I run it, I get the following error on the last line of code


Anybody can help me?


 Dim Context As Variant

    Set Context = CreateObject("Scripting.Dictionary")

    Dim LBInfo As Office.LabelInfo

    Set LBInfo = objExcel.SensitivityLabel.CreateLabelInfo()

    With LBInfo

        .AssignmentMethod = MsoAssignmentMethod.PRIVILEGED

        .LabelName = "company Confidential"

        .ContentBits = 4

        .IsEnabled = True

        .SetDate = Now()

        .LabelId = "my company label...."   ' company confidential Label

    End With

    objExcel.SensitivityLabel.SetLabel LBInfo, Context

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
4,349 questions
A family of Microsoft products used to create diagrams and vector graphics.
87 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,715 questions
0 comments No comments
{count} vote