Thread: Remove All VBA
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Remove All VBA

Hi,

This would after the SaveAs routine

Sub DeleteCode()
Msg = "Are you sure you want to delete Code from " & ActiveWorkbook.Name
Response = MsgBox(Msg, vbYesNo)
If Response = vbNo Then Exit Sub
On Error Resume Next
With ActiveWorkbook.VBProject
For X = .VBComponents.Count To 1 Step -1
.VBComponents.Remove .VBComponents(X)
Next X
For X = .VBComponents.Count To 1 Step -1
.VBComponents(X).CodeModule.DeleteLines _
1, .VBComponents(X).CodeModule.CountOfLines
Next X
End With
End Sub

Mike

"Otto Moehrbach" wrote:

Excel 2007 Win 7 64-bit
I have a wb with VBA code that does various things. The code then savesAS
the wb in another name. At that point, I want the same code to remove all
code from that wb and save the wb. Can that be done and how? Thanks for
your time. Otto

.