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

Didier 10 Reputation points
2024-07-01T07:52:02.21+00:00

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

image_2024-07-01_095046301

Anybody can help me?

Thx

 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.
5,164 questions
Visio
Visio
A family of Microsoft products used to create diagrams and vector graphics.
100 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.
4,006 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.