I am trying to write a macro that will delete the code behind a particular worksheet. I tried the following code but I keep getting a compile error after it deletes the lines.

Code Code:
  1. Dim VBProj As VBIDE.VBProject
  2. Dim VBComp As VBIDE.VBComponent
  3.  
  4. Set VBProj = ActiveWorkbook.VBProject
  5. Set CodeMod = ActiveWorkbook.VBProject.VBComponents("sheet1").CodeModule
  6.  
  7. CodeMod.DeleteLines 1, CodeMod.CountOfLines


First I get the following compile error:

"Only comments may appear after End Sub, End Function, or End Property"

I click "OK" and then I get the following run-time error:

"Method '_Default' of object 'Range' failed."

Regardless if I hit Debug or End, the program closes.

Any help is appreciated.
Chrissy