Option Explicit
Public Function BOOKNAME(Optional celRef As Range, _
Optional theType As Integer) As String
Dim myStr As String
If Not celRef Is Nothing Then
myStr = celRef.Parent.Parent.Name
Select Case theType
'1 = Book1.xls
'2 = Book1
Case 1, 0
BOOKNAME = myStr
Case 2
BOOKNAME = Left$(myStr, _
Len(myStr) - 4)
End Select
Else
myStr = Application.Caller.Parent.Parent.Name
Select Case theType
Case 1, 0
BOOKNAME = myStr
Case 2
BOOKNAME = Left$(myStr, Len(myStr) - 4)
End Select
End If
End Function