ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet Exists? Invisible Worksheets? (https://www.excelbanter.com/excel-programming/333373-worksheet-exists-invisible-worksheets.html)

Ken Loomis

Worksheet Exists? Invisible Worksheets?
 
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




Norman Jones

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







All times are GMT +1. The time now is 07:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com