Skip to content

Instantly share code, notes, and snippets.

@hexerei
Created October 7, 2015 19:27
Show Gist options
  • Save hexerei/8b3f532ae73124571ffa to your computer and use it in GitHub Desktop.
Save hexerei/8b3f532ae73124571ffa to your computer and use it in GitHub Desktop.
Selfdestructing VBA Code - Code to remove all VBA Modules from given Window - i.e. after copying Table, remove code
Dim x As Integer
With ActiveWindow
.Visible = False
.Activate
On Error Resume Next
For x = .VBProject.VBComponents.Count To 1 Step -1
.VBProject.VBComponents.Remove .VBComponents(x)
Next x
For x = .VBProject.VBComponents.Count To 1 Step -1
.VBProject.VBComponents(x).CodeModule.DeleteLines _
1, .VBProject.VBComponents(x).CodeModule.CountOfLines
Next x
End With
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment