现在的位置: 首页 > 综合 > 正文

Excel VBA: Delete Module After Running VBA Code. Deleting Modules via VBA Code

2012年09月16日 ⁄ 综合 ⁄ 共 509字 ⁄ 字号 评论关闭

The code below can be used to delete the module which houses the code. In other words, it deletes itself after running once.

You will have to go to Tools>Macro>Security - Trusted Publishers and check Trust access to Visual Basic Editor before running the code. Change "Module1" to suit.

  1. Sub DeleteThisModule()
  2. Dim vbCom As Object
  3.      
  4.     MsgBox "Hi, I will delete myself "
  5.      
  6.     Set vbCom = Application.VBE.ActiveVBProject.VBComponents
  7.     
  8.     vbCom.Remove VBComponent:= _
  9.     vbCom.Item("Module1")
  10.      
  11. End Sub

 

From: http://www.ozgrid.com/VBA/delete-module.htm

抱歉!评论已关闭.