View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Delete Code from Worksheet

Stolen from Chip Pearson's site:
http://www.cpearson.com/excel/vbe.htm

Option Explicit
Sub DeleteAllVBA()

Dim VBComp As VBIDE.VBComponent

With ActiveWorkbook
Set VBComp = .VBProject.VBComponents(.Worksheets("sheet1").Code Name)
End With
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Sub


JohnV wrote:

I have a workbook with a button that copies itself to a
new workbook. I then delete the button from the new
workbook but the code remains. In the VBA Editor I can
see the code attached to the worksheet.

Is there a way to delete the code or perhaps copy the
worksheet from the original workbook without the button
and associated code?

Thanks,
JohnV


--

Dave Peterson