检查是否VBProject在Microsoft Excel中使用VBA保护
使用下面的功能,您可以在尝试编辑项目之前检查VBProject是否受保护:
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
例如:
If ProtectedVBProject(ActiveWorkbook) Then Exit Sub