LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete sheet code

This doesn't delete code in sheets with tab names of Sheet1 and Sheet3.
Replace the sheet names you want to exclude with all lowercase versions of
their names.
Sub AAAtester1()

Dim VBComp As VBIDE.VBComponent, Wb As Excel.Workbook
Dim prop As VBIDE.Property
Set Wb = ActiveWorkbook
For Each VBComp In Wb.VBProject.VBComponents
Select Case VBComp.Type
Case vbext_ct_Document
If LCase(VBComp.Properties("Name")) < "sheet1" _
And LCase(VBComp.Properties("Name")) < "sheet3" Then
With VBComp.CodeModule
.DeleteLines StartLine:=1, Count:=.CountOfLines
End With
End If
Case Else
Wb.VBProject.VBComponents.Remove VBComp
End Select
Next VBComp
End Sub

--
Regards,
Tom Ogilvy


Gareth wrote in message
...
I am using the code below (which I got from this NG) in a macro that

copies
6 sheets from file A into a new file.

The sheet code is not required in the new file so is deleted using the
following:

Dim VBComp As VBIDE.VBComponent, Wb As Excel.Workbook
Set Wb = ActiveWorkbook
For Each VBComp In Wb.VBProject.VBComponents
Select Case VBComp.Type
Case vbext_ct_Document
With VBComp.CodeModule
.DeleteLines StartLine:=1, Count:=.CountOfLines
End With
Case Else
Wb.VBProject.VBComponents.Remove VBComp
End Select
Next VBComp

I now find that I need to keep the code in 2 sheets that are copied -

sheet1
and sheet2.

Could someone suggest how to alter the code in order to achieve this?

Thanks in advance

Gareth




 
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 chrisnsmith Excel Discussion (Misc queries) 4 March 8th 09 01:10 AM
What is the VBA code to delete a sheet without warning message? [email protected] Excel Discussion (Misc queries) 2 August 9th 05 04:16 PM
Delete the code in ThisWorkbook Darrin Henry Excel Programming 1 October 1st 03 11:10 PM
VBA code to delete VBA code in another Workbook Chip Pearson Excel Programming 0 September 15th 03 03:54 PM
Code to not display delete sheet alerts John[_46_] Excel Programming 2 August 25th 03 01:44 PM


All times are GMT +1. The time now is 12:56 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"