View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
michael.beckinsale michael.beckinsale is offline
external usenet poster
 
Posts: 274
Default Trying to delete sheet code with VBA

Hi All,

Glad this newsgroup still appears to be working!

I am building a consolidation type workbook that imports specific
sheets from all workbooks in a folder. All of the sheets to be
imported have Worksheet_Activate events coded into them and l need to
remove the code either at the time of copying the sheet into the
consolidator or by looping through each sheet and if the tab color
index is 24 then delete the code.

Below is some sample code which seems to work in a test file but bombs
out in the consolidator file on the Application.VBE...... line. I have
set a reference to the VBA Extensibilty 5.3 and am using XL2003

I have tried many different variations but l just can't seem to get it
quite right! Any help would be gratefully appreciated.



Sub TestDeleteVBA()

Dim Filename As String
Filename = ActiveWorkbook.Name

For Each Sht1 In Workbooks(Filename).Worksheets
If Sht1.Tab.ColorIndex = 24 Then
Sht1.Activate
With
Application.VBE.ActiveVBProject.VBComponents(Sht1. Name).CodeModule
.DeleteLines StartLine:=1, Count:=.CountOfLines
End With
End If
Next Sht1

End Sub

Regards

Michael