|
-
Jun 24th, 2010, 12:20 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Delete code in workbooks using a macro
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:
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Set VBProj = ActiveWorkbook.VBProject
Set CodeMod = ActiveWorkbook.VBProject.VBComponents("sheet1").CodeModule
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
-
Jun 24th, 2010, 12:37 PM
#2
Re: Delete code in workbooks using a macro
Where are you trying to sub this code from?
It sounds like you are running it from the declarations section rather than from an actual sub routine.
-
Jun 24th, 2010, 12:39 PM
#3
Thread Starter
Hyperactive Member
Re: Delete code in workbooks using a macro
No, it is in a sub within a module...
vb Code:
Sub DeleteCode() Dim VBProj As VBIDE.VBProject Dim VBComp As VBIDE.VBComponent Workbooks("07540.xls").Activate Set VBProj = Workbooks("07540.xls").VBProject Set CodeMod = ActiveWorkbook.VBProject.VBComponents("sheet1").CodeModule CodeMod.DeleteLines 1, CodeMod.CountOfLines End Sub
-
Jun 24th, 2010, 12:41 PM
#4
Thread Starter
Hyperactive Member
Re: Delete code in workbooks using a macro
The code actually runs, it is AFTER it deletes the lines that it gives the error.
-
Jun 24th, 2010, 01:05 PM
#5
Thread Starter
Hyperactive Member
Re: Delete code in workbooks using a macro
Nevermind... the code works... the problem is on another row because of the deletion. Sorry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|