수많은 매크로로 작업하고 매크로가 현재 Excel 통합 문서의 모든 기존 코드를 지우려면 다음 기사가 반드시 도움이 될 것입니다.

통합 문서 또는 문서에서 모든 매크로를 삭제하려면 아래 매크로를 사용할 수 있습니다.

이 절차는 편집없이 Excel과 Word에서 모두 사용할 수 있습니다.

Sub RemoveAllMacros(objDocument As Object)

' deletes all VBProject components from objDocument

' removes the code from built-in components that can't be deleted

' use like this: RemoveAllMacros ActiveWorkbook ' in Excel

' or like this: RemoveAllMacros ActiveWorkbookDocument ' in Word

' requires a reference to the

' Microsoft Visual Basic for Applications Extensibility library

Dim i As Long, l As Long

If objDocument Is Nothing Then Exit Sub

i = 0

On Error Resume Next

i = objDocument.VBProject.VBComponents.Count

On Error GoTo 0

If i < 1 Then ' no VBComponents or protected VBProject

MsgBox "The VBProject in " & objDocument.Name & _

" is protected or has no components!", _

vbInformation, "Remove All Macros"

Exit Sub

End If

With objDocument.VBProject

For i = .VBComponents.Count To 1 Step -1

On Error Resume Next

.VBComponents.Remove .VBComponents(i)

' delete the component

On Error GoTo 0

Next i

End With

With objDocument.VBProject

For i = .VBComponents.Count To 1 Step -1

l = 1

On Error Resume Next

l = .VBComponents(i).CodeModule.CountOfLines

.VBComponents(i).CodeModule.DeleteLines 1, l

' clear lines

On Error GoTo 0

Next i

End With

End Sub