How to get the sheet name from Application.Caller?
Asked Answered
M

3

5

It is possible to get the calling workbook name Application.Caller.Worksheet.Parent.Name and cell address using Application.Caller.Address, for a function called in Excel.

Is there a way to get the sheet name, e.g. Sheet1, using Application.Caller?

Mudfish answered 4/6, 2013 at 11:55 Comment(0)
V
9

you pretty much had it already

Application.Caller.Worksheet.Name
Vespertilionine answered 4/6, 2013 at 11:56 Comment(1)
Not working in VBA 7.0 not evening returning as a variable. The caller is a checkbox.Advantageous
M
1
Dim called_by As Variant
Dim x as string
Set called_by = Application.Caller
x = called_by.Parent.Application.Activesheet.Name

works fine in my application when calling this function within a cell.

Mayfair answered 20/11, 2019 at 10:54 Comment(0)
C
0

I know this is old, but application.caller represents what is happening in the active sheet. So why not simply Dim Mysheet as string and then use the code as follows...

Mysheet = activesheet.name

or if you want both the item that called the macro (Application.Caller) and the sheet name, then as follows:

Dim myStr As String, myShtNm As String
myShtNm = ActiveSheet.Name
myStr = Application.Caller
Conlan answered 23/7, 2024 at 19:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.