모든 종류의 모듈을 삭제할 수는 없으며 워크 시트, 차트 및 ThisWorkbook에 대한 코드 모듈을 삭제할 수 없습니다. 이러한 모듈에서는 모듈 자체 대신 콘텐츠를 삭제해야합니다.

Sub DeleteModuleContent(ByVal wb As Workbook, _

ByVal DeleteModuleName As String)

' deletes the contents of DeleteModuleName in wb

' use this if you can't delete the module

On Error Resume Next

With wb.VBProject.VBComponents(DeleteModuleName).CodeModule

.DeleteLines 1, .CountOfLines

End With

On Error GoTo 0

End Sub

예 :

DeleteModuleContent ActiveWorkbook, "Sheet1"