View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Worksheet Exists? Invisible Worksheets?

Hi Ken,

Try:

Sub TestIt()

If Not SheetExists("Oldfiles", ActiveWorkbook) Then
Worksheets.Add
With ActiveSheet
.Name = "OldFiles"
.Visible = xlVeryHidden
End With
End If
End Sub

Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function


---
Regards,
Norman



"Ken Loomis" wrote in message
...
I need to test for the existence of a specific worksheet in the active
workbook.

The sheet name will always be "OldFiles" and I need to create it if is
doesn't exist.

Also, is there a way to make the new sheet ("OldFiles") invisible?

Ken