- Sub DeleteProcedure()
- Dim moduleName As String
- Dim procedureName As String
- Dim startLine As Long
- Dim endLine As Long
-
- moduleName = "模块1" ' 替换为您要删除过程的模块名称
- procedureName = "冬天" ' 替换为您要删除的过程名称
-
- Set codeModule = ThisWorkbook.VBProject.VBComponents(moduleName).codeModule
-
- startLine = codeModule.ProcStartLine(procedureName, vbext_pk_Proc)
- endLine = codeModule.ProcCountLines(procedureName, vbext_pk_Proc)
-
- codeModule.DeleteLines startLine, endLine
-
- MsgBox "过程删除成功!", vbInformation
- End Sub
复制代码
来源于AI,注意excel必须勾选“信任VB工程访问
(1)EXCEL已设置: 工具(T)-宏(M)-安全性(M)-可靠发行商(T)-勾选了“信任对于VB项目的访问(V)”
|