View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Using VB, remove a certain section from ThisWorkbook

Try

Sub DeleteWBOpen()
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim ProcLen As Long

Set CodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With CodeMod
StartLine = .ProcStartLine("Workbook_Open", vbext_pk_Proc)
ProcLen = .ProcCountLines("Workbook_Open", vbext_pk_Proc)
.DeleteLines StartLine, ProcLen
End With
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Wed, 19 Nov 2008 11:14:31 -0500, "PCLIVE"
wrote:


Using the following code I can remove the VB code contained in ThisWorkbook.

With ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
.DeleteLines 1, .CountOfLines
End With


Is there a way that I can specify to remove only the Workbook_Open portion
of the ThisWorkbook code?
Example:

"Private Sub Workbook_Open()"
<some code
End Sub


The rest of the code in ThisWorkbook I'd like to leave untouched. Can this
be done

Thanks,
Paul