Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete code LiAD Excel Programming 6 December 16th 09 07:36 PM
Can code delete code Steph[_6_] Excel Programming 12 October 7th 05 08:04 PM
Code to delete a Line in a another code helmekki[_88_] Excel Programming 1 August 8th 05 01:14 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM
VBA code to delete VBA code in another Workbook Chip Pearson Excel Programming 0 September 15th 03 03:54 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"