Share via


Protection Property [Visio 2003 SDK Documentation]

As it applies to the Document object.

Determines how a document is protected from user customization.

retVal = object**.Protection** ([bstrPassword])

object**.Protection** ([bstrPassword]****) = newValue

retVal     VisProtection. The current protection settings.

object     Required. An expression that returns a Document object.

bstrPassword     Not used.

newValue     Required VisProtection. The new protection settings.

Version added

2002

Remarks

Beginning with Microsoft Office Visio 2003, the Protection property ignores the bstrPassword argument both when you get and when you set the value of the property.

This property is the equivalent of checking the Styles, Shape, Preview, Backgrounds, and Master shapes boxes in the Protect Document dialog box (in the Drawing Explorer, right-click the drawing name, and then click Protect Document).

The value of retVal and newValue can be a combination of the following VisProtection constants.

Constant Value

visProtectNone

&H0

visProtectStyles

&H1

visProtectShapes

&H2

visProtectMasters

&H4

visProtectBackgrounds

&H8

visProtectPreviews

&H10

As it applies to the MenuSet and Toolbar objects.

Determines how an object is protected from user customization.

intRet = object**.Protection**

object**.Protection** = intExpression

intRet     Integer. The existing protections for a MenuSet or Toolbar object.

object     Required. An expression that returns a MenuSet or Toolbar object.

intExpression     Required Integer. The new protections for a MenuSet or Toolbar object.

Version added

2000

Remarks

The value of intExpression can be one or a combination of the following constants declared by the Visio type library in VisUIBarProtection.

Constant Value Description

visBarNoProtection

0

No protection.

visBarNoCustomize

1

Cannot be customized.

visBarNoResize

2

Cannot be resized.

visBarNoMove

4

Cannot be moved.

visBarNoChangeDock

16

Cannot be docked or floating.

visBarNoVerticalDock

32

Cannot be docked vertically.

visBarNoHorizontalDock

64

Cannot be docked horizontally.

Example

As it applies to the Toolbar object.

This example shows how to use the Protection property to prevent users from docking a custom toolbar. The example adds a custom toolbar to the Toolbars collection and then adds a button to the toolbar. The toolbar appears in the Microsoft Office Visio user interface and is available while the document is active.

To restore Visio's built-in toolbars after you run this macro, call the ThisDocument.ClearCustomToolbars method.

Sub Protection_Example()
 
    Dim vsoUIObject As Visio.UIObject 
    Dim vsoToolbars As Visio.Toolbars 
    Dim vsoToolbar As Visio.Toolbar 
    Dim vsoToolbarItem As Visio.ToolbarItem
 
    'Check whether there are document custom toolbars. 
    If ThisDocument.CustomToolbars Is Nothing Then

        'Check whether there are application custom toolbars. 
        If Visio.Application.CustomToolbars Is Nothing Then

            'Use the built-in toolbars. 
            Set vsoUIObject = Visio.Application.BuiltInToolbars(0) 

        Else

            'Use the application custom toolbars. 
            Set vsoUIObject = Visio.Application.CustomToolbars.Clone
 
        End If  

    Else

        'Use the document custom toolbars. 
        Set vsoUIObject = ThisDocument.CustomToolbars 

    End If  

    'Get the Toolbars collection for the drawing window context. 
    Set vsoToolbars = vsoUIObject.ToolbarSets.ItemAtID( _ 
        Visio.visUIObjSetDrawing).Toolbars 

    'Add a toolbar to the collection. 
    Set vsoToolbar = vsoToolbars.Add 
    With vsoToolbar 

        'Set the title of the toolbar. 
        .Caption = "My New Toolbar" 

        'Float the toolbar at coordinates (300,200). 
        .Position = Visio.visBarFloating 
        .Left = 300 
        .Top = 200 

        'Disallow docking the new toolbar. 
        .Protection = Visio.visBarNoHorizontalDock _ 
            + Visio.visBarNoVerticalDock 

    End With  

    'Add an item to the toolbar. 
    Set vsoToolbarItem = vsoToolbar.ToolbarItems.Add 
    With vsoToolbarItem 

        'Set the new item to be a button. 
        .CntrlType = Visio.visCtrlTypeBUTTON 

        'Set the icon of the new button. 
        .FaceID = Visio.visIconIXCUSTOM_CARDS 

        'Set the CmdNum property of the new button 
        .CmdNum = 1 

        'Set the Width property of the new button
        'wide enough that the toolbar name is readable. 
        .Width = 100 

    End With 

    'Tell Visio to use the new UIObject object while
    'this document is active.
    ThisDocument.SetCustomToolbars vsoUIObject 

End Sub

Applies to | Document object | MenuSet object | Toolbar object

See Also