ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code to delete vba code (https://www.excelbanter.com/excel-programming/442849-code-delete-vba-code.html)

Louis

code to delete vba code
 
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("ThisWorkboo k").CodeModule
StartLine = .ProcStartLine("Workbook_Open", 0)
If StartLine Then
LineCount = .ProcCountLines("Workbook_Open", 0)
.DeleteLines StartLine, LineCount
End If
End With
End Sub

Pieter[_6_]

code to delete vba code
 
On May 27, 12:57*pm, Louis 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("ThisWorkboo k").CodeModule
* * StartLine = .ProcStartLine("Workbook_Open", 0)
* * If StartLine Then
* * * * LineCount = .ProcCountLines("Workbook_Open", 0)
* * * * .DeleteLines StartLine, LineCount
* * End If
End With
End Sub




All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com