Created
March 13, 2013 10:52
-
-
Save botaor/5151052 to your computer and use it in GitHub Desktop.
Get the names of the sheets in an Excel Workbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function SHEETNAME(Optional ShtOrder As Long = 0, _ | |
Optional ByVal IncludeHiddenSheet As Boolean = False) As Variant | |
'// Developed by Kris @ ExcelFox.com | |
Dim ShtCount As Long | |
Dim i As Long | |
Dim n As Long | |
ShtCount = ThisWorkbook.Worksheets.Count | |
If ShtOrder = 0 Then | |
SHEETNAME = ActiveSheet.Name | |
Exit Function | |
End If | |
SHEETNAME = CVErr(xlErrRef) | |
Application.Volatile | |
SHEETNAME = "" | |
With ThisWorkbook | |
If IncludeHiddenSheet Then | |
If ShtOrder > ShtCount Then Exit Function | |
SHEETNAME = .Worksheets(ShtOrder).Name | |
Else | |
For i = 1 To ShtCount | |
If .Worksheets(i).Visible = -1 Then | |
n = n + 1 | |
If n = ShtOrder Then | |
SHEETNAME = .Worksheets(i).Name | |
Exit Function | |
End If | |
End If | |
Next | |
End If | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment