|
回复 35楼 涵辛 的帖子
可以参考下面的代码:
Sub CheckModel()
Dim WB As Workbook
Dim Vbc As Variant
Dim I%, mStr$
Dim Self As Boolean
Self = False
On Error Resume Next
For Each WB In Application.Workbooks
Debug.Print WB.Name
Debug.Print WB.VBProject.Protection
If WB.VBProject.Protection = 1 Then Debug.Print WB.Name & " is being protected"
For Each Vbc In WB.VBProject.VBComponents
Debug.Print Vbc.Type & " " & Vbc.Name
For I = 1 To Vbc.CodeModule.CountOfLines
mStr = Vbc.CodeModule.Lines(I, 1)
'SELF
If mStr = " 'SELF" Then Self = True
If mStr = " 'NSELF" Then Self = False
If UCase(mStr) Like "*XLSTART*" And Not Self Then
If MsgBox("是否删除代码: " & mStr & "??", vbYesNo + vbQuestion, " 发现" & WB.Name & " 有异常代码) = vbYes Then Vbc.CodeModule.DeleteLines I, 1
End If
'NSELF
Debug.Print mStr
Next
Next
Next
End Sub |
|