Check if a VBProject is protected

 2000-02-05    VBE    0    53

With the function below you can check if a VBProject is protected before you try to edit the project:

Function ProtectedVBProject(ByVal wb As Workbook) As Boolean
' requires a reference to the Microsoft Visual Basic Extensibility library
' returns TRUE if the VB project in the active document is protected
Dim VBC As Integer
    VBC = -1
    On Error Resume Next
    VBC = wb.VBProject.VBComponents.Count
    On Error GoTo 0
    If VBC = -1 Then
        ProtectedVBProject = True
    Else
        ProtectedVBProject = False
    End If
End Function
Example:
If ProtectedVBProject(ActiveWorkbook) Then Exit Sub


Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.