ValidationRules.Add method (Visio)

Adds a new, empty ValidationRule object to the ValidationRules collection of the document.

Syntax

expression.Add (NameU)

expression A variable that represents a ValidationRules object.

Parameters

Name Required/Optional Data type Description
NameU Required String The universal name to assign to the new validation rule.

Return value

ValidationRule

Remarks

If the NameU parameter is not a valid string, Visio returns an Invalid Parameter error.

The default property values of the new validation rule are as follows:

Example

The following sample code is based on code provided by: David Parker

The following Visual Basic for Applications (VBA) example shows how to use the Add method to add a new validation rule named "UngluedConnector" to an existing validation rule set named "Fault Tree Analysis" in the active document.

Public Sub Add_Example()

    Dim vsoValidationRule As Visio.ValidationRule
    Dim vsoValidationRuleSet As Visio.ValidationRuleSet
    Dim strValidationRuleSetNameU As String
    Dim strValidationRuleNameU As String
    
    strValidationRuleSetNameU = "Fault Tree Analysis"
    strValidationRuleNameU = "UngluedConnector"
    
    Set vsoValidationRuleSet = ActiveDocument.Validation.RuleSets(strValidationRuleSetNameU)
    Set vsoValidationRule = vsoValidationRuleSet.Rules.Add(strValidationRuleNameU)

End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.