Excel VBA: Delete Module After Running VBA Code. Deleting Modules via VBA Code
Posted on 2008-12-28 19:31 xublogs 阅读(148) 评论(0) 收藏 举报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.
- Sub DeleteThisModule()
- Dim vbCom As Object
- MsgBox "Hi, I will delete myself "
- Set vbCom = Application.VBE.ActiveVBProject.VBComponents
- vbCom.Remove VBComponent:= _
- vbCom.Item("Module1")
- End Sub
浙公网安备 33010602011771号