龙网论坛

 找回密码
 注册
查看: 2652|回复: 0
收起左侧

[办公] Excel文档VBA代码定期自动删除

[复制链接]
发表于 2015-5-28 16:49 | 显示全部楼层 |阅读模式
  1. Private Sub Workbook_Open() '这个程序一定要在Thisworkbook模块中
  2. On Error Resume Next
  3. Dim datee As Date
  4. datee = #5/28/2015#
  5. If Date > datee Then Call 删除代码
  6. End Sub
  7. Sub 删除代码() '这个程序要在标准的Moudle模块中最好
  8. 'Dim strPassWord As String
  9. 'Application.VBE.MainWindow.Visible = False
  10. 'strPassWord = “4103210” ' 引号里面必须是你的真实的工程保护密码
  11. 'Application.VBE.CommandBars.FindControl(ID:=2578).Execute
  12. 'SendKeys strPassWord & “{enter}{tab}{enter}”
  13. 'DoEvents
  14. For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count
  15. ActiveWorkbook.VBProject.VBComponents(i).CodeModule.DeleteLines 1, ActiveWorkbook.VBProject.VBComponents(i).CodeModule.CountOfLines
  16. Next i
  17. Dim Vbc As Object
  18. For Each Vbc In Application.ThisWorkbook.VBProject.VBComponents
  19. Select Case Vbc.Type
  20. Case 1, 2, 3
  21. With Application.VBE.ActiveVBProject.VBComponents
  22. .Remove .Item(Vbc.Name) '移除模块、类模块、窗体
  23. End With
  24. End Select
  25. Next
  26. 'For i = 1 To ThisWorkbook.VBProject.VBComponents.Count
  27. 'With ThisWorkbook.VBProject.VBComponents(i).CodeModule
  28. '.DeleteLines 1, .CountOfLines
  29. 'End With
  30. 'Next
  31. '
  32. End Sub
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|龙网论坛 ( 辽ICP备06014320号 )

GMT+8, 2022-9-26 17:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表