
Sub CATMain()
    Dim doc As PartDocument
    Set doc = GetBluePosionPartDoc()
    
    Dim msg As String
    If doc Is Nothing Then
        msg = "There is no blue position PartDocument."
    Else
        msg = "The blue position PartDocument is " & doc.Name & " ."
    End If
    
    MsgBox msg
End Sub
Private Function GetBluePosionPartDoc() As PartDocument
    
    Set GetBluePosionPartDoc = Nothing
    
    Dim sel As selection
    Set sel = CATIA.ActiveDocument.selection
    
    CATIA.HSOSynchronized = False
    
    With sel
        .Clear
        .Search "CATPrtSearch.Plane,in"
        
        If .Count2 < 1 Then GoTo fin
        
        Set GetBluePosionPartDoc = .Item2(1).Value.Parent.Parent
        .Clear
    End With
    
fin:
    CATIA.HSOSynchronized = True
    
End Function 
 
                                 
                                 
                 
             
                            