PC Review


Reply
Thread Tools Rate Thread

code to delete vba code

 
 
Louis
Guest
Posts: n/a
 
      27th May 2010
I hve found this code to delete all code within a workbook.

As soon the code reach the line If "ThisWorkbook.VBProject.Protection Then
Exit Sub" the code stop and a failure message appear "if without end if "

could you please help me with this issue.

Thanks


Sub ClearThisWorkbookCode()

Dim StartLine As Long, LineCount As Long
If ThisWorkbook.VBProject.Protection Then
Exit Sub
On Error Resume Next
With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
StartLine = .ProcStartLine("Workbook_Open", 0)
If StartLine Then
LineCount = .ProcCountLines("Workbook_Open", 0)
.DeleteLines StartLine, LineCount
End If
End With
End Sub
 
Reply With Quote
 
 
 
 
Pieter
Guest
Posts: n/a
 
      27th May 2010
On May 27, 12:57*pm, Louis <Lo...@discussions.microsoft.com> wrote:

Put an "End If" just after the Exit Sub that will clear the error.

Pieter



> I hve found this code to delete all code within a workbook.
>
> As soon the code reach the line If "ThisWorkbook.VBProject.Protection Then
> Exit Sub" the code stop and a failure message appear "if without end if "
>
> could you please help me with this issue.
>
> Thanks
>
> Sub ClearThisWorkbookCode()
>
> Dim StartLine As Long, LineCount As Long
> If ThisWorkbook.VBProject.Protection Then
> * * Exit Sub
> On Error Resume Next
> With ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
> * * StartLine = .ProcStartLine("Workbook_Open", 0)
> * * If StartLine Then
> * * * * LineCount = .ProcCountLines("Workbook_Open", 0)
> * * * * .DeleteLines StartLine, LineCount
> * * End If
> End With
> End Sub


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Will deleting a Form delete attached code? AND How to see ALL code in dB ? Mel Microsoft Access 2 30th Apr 2007 08:25 PM
Code to delete a Line in a another code helmekki Microsoft Excel Programming 1 8th Aug 2005 01:14 AM
[New] Zipoid - ZIP Code, City Name and Area Code Lookup - Zip Code to Zip Code Distance Calculation Mel Freeware 0 22nd Jul 2005 04:13 PM
code to delete a user/ code to move users into and out of groups =?Utf-8?B?dHc=?= Microsoft Access Security 11 30th May 2005 06:59 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Microsoft Excel Programming 0 27th Jan 2004 07:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:57 PM.