PDA

View Full Version : sheets exist



lior03
01-23-2006, 07:45 AM
hello
sorry for asking again.
i want to check if a sheet name exist and then generate a list that will count all lines of code in all mudules.if the sheet is missing then add sheet.
i got stuck an lost

Sub showcomponents()
Dim ws As Worksheet
For Each ws In Worksheets
If Not SheetExists("components") Then
Worksheets.Add.Name = "components"
End If
Next ws
With Sheets("components")
Cells.HorizontalAlignment = xlRight
Cells.ClearContents
Dim vbp As VBProject
Dim numcomponents As Integer
Dim i As Integer
Set vbp = ActiveWorkbook.VBProject
numcomponents = vbp.VBComponents.Count
Application.ScreenUpdating = False
On Error Resume Next
End With
For i = 1 To numcomponents
Cells(i, 1) = vbp.VBComponents(i).Name
Select Case vbp.VBComponents(i).Type
Case 1
Cells(i, 2) = "module"
Case 2
Cells(i, 2) = "class module"
Case 3
Cells(i, 2) = "userform"
Case 100
Cells(i, 2) = "document module"
End Select
Cells(i, 3) = _
vbp.VBComponents(i).CodeModule.CountOfLines
Next i
End Sub


thanks

Bob Phillips
01-23-2006, 08:10 AM
Well apart from that fact that you don't need tgo loope through all the sheets to check if components exists, a single check suffices, it seems fine to me. That point I made won't actually make any difference, it is just wasteful, as once created it fails the test next time.