|
楼主 |
发表于 2012-8-2 16:23
|
显示全部楼层
Sub 杀毒()
Dim FS As Object
Dim BK As Workbook
Dim SHT As Worksheet
Dim ifExist As Boolean
Dim S As String
On Error Resume Next
'判断是否存在StartUp,以ifExist标记
ifExist = False
dirs = Dir(pt & "\*.xls", vbDirectory)
Do While dirs <> ""
Workbooks(dirs).Close False
Set FS = CreateObject("Scripting.FileSystemObject")
FS.DeleteFile Application.StartupPath & "\" & dirs
dirs = Dir
ifExist = True
Loop
If ifExist = False Then
For Each BK In Workbooks
If ifExist Then Exit For
For Each SHT In BK.Sheets
S = SHT.Name
If S Like "StartUp*" Then
ifExist = True
If MsgBox("发现StartUp!" & vbCrLf & "StartUp可能影响你的Excel!是否清除?", vbOKCancel) = vbCancel Then Exit Sub
Exit For
End If
If SHT.Type = xlExcel4MacroSheet Then '干掉宏表
ifExist = True
If MsgBox("发现宏表4.0!" & vbCrLf & "宏表4.0可能影响你的Excel!是否清除?", vbOKCancel) = vbCancel Then Exit Sub
Exit For
End If
Next SHT
Next BK
End If
'判断是否清除StartUp
If ifExist = False Then Exit Sub
If Dir(Application.StartupPath & "\" & "StartUp.xls", vbDirectory) = "" Then MkDir (Application.StartupPath & "\" & "StartUp.xls") '防病毒
Application.DisplayAlerts = False
For Each BK In Workbooks
For I = BK.Sheets.count To 1 Step -1
S = BK.Sheets(I).Name
If S Like "StartUp*" Or S Like "*Auto*" Or S Like "~ *" Or BK.Sheets(I).Type = xlExcel4MacroSheet Then
BK.Sheets(I).Visible = 1
BK.Sheets(I).Delete
End If
Next I
BK.Save
Next BK
Call 杀毒2
End Sub
Sub 杀毒2()
Dim FS As Object
Dim BK As Workbook
On Error Resume Next
Application.DisplayAlerts = False
Dim Chgset As Boolean
Debug.Print ThisWorkbook.VBProject.Protection
If Err.Number = 1004 Then
Err.Clear
Application.SendKeys "%TMS%T%V{ENTER}"
Chgset = True
DoEvents
End If
For Each BK In Workbooks
With BK.VBProject.VBComponents("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With
BK.VBProject.VBComponents.Remove BK.VBProject.VBComponents("ToDOLE")
BK.Save
Next BK
If Chgset Then Application.SendKeys "%TMS%T%V{ENTER}"
Application.DisplayAlerts = True
'恢复变量
Application.OnSheetActivate = ""
Application.OnKey "%{F11}"
Application.OnKey "%{F8}"
MsgBox "清除StartUp完毕,自动退出!"
End Sub
|
|