Hi All,
I need to return the name of an active workbook, but I cannot use ThisWorkbook because my code resides in an add-in.
I have managed to make a function to accomplish this, but it seems messier than it ought to be. Does any one know of a slicker way to do this?
I'm using Excel 2010 and windows 7
The code for my current function is below:
Function GetBook(myRange As Range) As String
' Returns name of the workbook in which a range is located as a String.
Dim address As String
Dim nameSplit As Variant
Dim bookName As String
address = myRange.address(external:=True)
nameSplit = Split(address, "]")
bookName = Replace(nameSplit(0), "'", "", 1)
GetBook = Replace(bookName, "[", "", 1)
End Function
Thanks,
Nolan
I need to return the name of an active workbook, but I cannot use ThisWorkbook because my code resides in an add-in.
I have managed to make a function to accomplish this, but it seems messier than it ought to be. Does any one know of a slicker way to do this?
I'm using Excel 2010 and windows 7
The code for my current function is below:
Function GetBook(myRange As Range) As String
' Returns name of the workbook in which a range is located as a String.
Dim address As String
Dim nameSplit As Variant
Dim bookName As String
address = myRange.address(external:=True)
nameSplit = Split(address, "]")
bookName = Replace(nameSplit(0), "'", "", 1)
GetBook = Replace(bookName, "[", "", 1)
End Function
Thanks,
Nolan