Share via


IsValidObject Method [Publisher 2003 VBA Language Reference]

Determines whether the specified object variable references a valid object and returns a Boolean value: True if the specified variable that references an object is valid, False if the object referenced by the variable has been deleted.

expression.IsValidObject(Object)

expression Required. An expression that returns one of the objects in the Applies To list.

Object  Required Object. A variable that references an object.

Example

This example formats the line of a valid object.

Sub ValidShape(shpObject As Shape)

    If Application.IsValidObject(Object:=shpObject) = True Then
        With shpObject.Line
            .DashStyle = msoLineRoundDot
            .ForeColor.RGB = RGB(Red:=158, Green:=50, Blue:=208)
            .Weight = 5
        End With
    End If

End Sub

Use the following subroutine to call the above subroutine.

Sub CallValidShape()
    Call ValidShape(shpObject:=ActiveDocument.Pages(1).Shapes(2))
End Sub

Applies to | Application Object