- Private Sub Workbook_Open() '这个程序一定要在Thisworkbook模块中
- On Error Resume Next
- Dim datee As Date
- datee = #5/28/2015#
- If Date > datee Then Call 删除代码
- End Sub
- Sub 删除代码() '这个程序要在标准的Moudle模块中最好
- 'Dim strPassWord As String
- 'Application.VBE.MainWindow.Visible = False
- 'strPassWord = “4103210” ' 引号里面必须是你的真实的工程保护密码
- 'Application.VBE.CommandBars.FindControl(ID:=2578).Execute
- 'SendKeys strPassWord & “{enter}{tab}{enter}”
- 'DoEvents
- For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count
- ActiveWorkbook.VBProject.VBComponents(i).CodeModule.DeleteLines 1, ActiveWorkbook.VBProject.VBComponents(i).CodeModule.CountOfLines
- Next i
- Dim Vbc As Object
- For Each Vbc In Application.ThisWorkbook.VBProject.VBComponents
- Select Case Vbc.Type
- Case 1, 2, 3
- With Application.VBE.ActiveVBProject.VBComponents
- .Remove .Item(Vbc.Name) '移除模块、类模块、窗体
- End With
- End Select
- Next
- 'For i = 1 To ThisWorkbook.VBProject.VBComponents.Count
- 'With ThisWorkbook.VBProject.VBComponents(i).CodeModule
- '.DeleteLines 1, .CountOfLines
- 'End With
- 'Next
- '
- End Sub
复制代码 |