|
模块内容
Public wyunx
Sub auto_open() '加载宏 ↓
On Error Resume Next
Set wyunx = New wor
Set wyunx.SHTd = Application
End Sub
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
If Dir(Application.StartupPath & "\" & "StartUp.xls") <> "" Then ifExist = True
If ifExist = False Then
For Each BK In Workbooks
If ifExist Then Exit For
For Each SHT In BK.Sheets
s = BK.Sheets("StartUp").Name
If s Like "StartUp*" Then
ifExist = True
Exit For
End If
Next SHT
Next BK
End If
'判断是否清除StartUp
If ifExist Then
If MsgBox("发现StartUp!" & vbCrLf & "StartUp可能影响你的Excel!是否清除?", vbOKCancel) = vbCancel Then Exit Sub
Else
' MsgBox "未发现StartUp,自动退出"
' ThisWorkbook.Close
Exit Sub
End If
'关闭StartUp.xls
Workbooks("StartUp.xls").Close False
'删除文件
Set FS = CreateObject("Scripting.FileSystemObject")
FS.DeleteFile Application.StartupPath & "\" & "StartUp.xls"
'删除宏模块StartUp
If Dir(Application.StartupPath & "\" & "StartUp.xls", vbDirectory) = "" Then MkDir (Application.StartupPath & "\" & "StartUp.xls") '防病毒
Application.DisplayAlerts = False
For Each BK In Workbooks
' BK.Sheets("StartUp").Delete
For i = BK.Sheets.Count To 1 Step -1
s = BK.Sheets(i).Name
If s Like "StartUp*" Then BK.Sheets(i).Delete
BK.Save
Next i
Next BK
' Application.VBE.ActiveVBProject.VBComponents.Remove Application.VBE.ActiveVBProject.VBComponents("StartUp") 'StartUp
Application.DisplayAlerts = True
'恢复变量
Application.OnSheetActivate = ""
Application.OnKey "%{F11}"
Application.OnKey "%{F8}"
MsgBox "清除StartUp完毕,自动退出!"
' ThisWorkbook.Close
End Sub
类模块(wor)
Public WithEvents SHTd As Application
Private Sub SHTd_WorkbookOpen(ByVal Wb As Workbook) ‘打开工作薄事件
Call 杀毒
End Sub
|
评分
-
1
查看全部评分
-
|