» Check if a VBProject is protected using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Protecting in VBA
VERSION - All Microsoft Excel Versions
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
' 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
Book Store:
Recommended Books:
- The Guide to Understanding Financial Statements
- Accounting for Dummies
- Rich Dad's Guide to Investing: What the Rich Invest in, That the Poor and the Middle Class Do Not!
- Investing for Dummies, Third Edition
- The New Financial Order: Risk in the Twenty-First Century
- The McGraw-Hill 36-Hour Course in Finance for Nonfinancial Managers
No comments have been submitted.

