code to delete vba code

L

Louis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top