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.
- SubDeleteThisModule()
- DimvbComAsObject
- MsgBox"Hi,Iwilldeletemyself"
- SetvbCom=Application.VBE.ActiveVBProject.VBComponents
- vbCom.RemoveVBComponent:=_
- vbCom.Item("Module1")
- EndSub
本文提供了一个使用VBA删除指定模块的示例代码,该代码能够在运行一次后自行删除所在模块。运行前需设置信任访问Visual Basic编辑器。
2240

被折叠的 条评论
为什么被折叠?



