How to get current sheet (not activesheet) name from function? By "current sheet" I mean sheet name where function placed and called from.
I trying get like that
Function MySheet()
MySheet = Application.Caller.Worksheet.Name
MsgBox MySheet
End Function
but i get error object required.
You are going to have to be careful in how you call that function. You've supplied very little detail on what you want to do with it.
Th above at least attempts to make some sort of determination of what
Application.Caller
is before using it to determine the associated worksheet object's name.You can read more at Application.Caller Property (Excel).
Is it
Me
you're looking for?This is what you want if by "sheet name where function placed" you mean, the Sheet module in which the function code is placed. (Documentation).
However, if you mean, the sheet containing the cell from which the user-defined function is called, you can use:
Application.Caller
returns aRange
object referring to the cell; this range'sParent
is then the sheet.