本文介绍了Application.Caller对象需要错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从功能中获取当前工作表(不是活动表)名称?通过当前工作表,我的意思是表格名称,功能放置和调用。



我尝试得到这样的

 函数MySheet()

MySheet = Application.Caller.Worksheet.Name
MsgBox MySheet
结束函数

但我得到需要的错误对象。

解决方案

你将要小心如何调用那个功能。您已经提供了关于您要做什么的细节。

 函数MySheet()
选择案例TypeName(Application.Caller)
案例范围
MySheet = Application.Caller.Parent.Name
案例String
MySheet = Application.Caller
案例错误
MySheet =错误
案例Else
MySheet =未知
结束选择
结束功能
/ pre>

至少在使用它之前,尝试对某些 Application.Caller 做出某种确定确定相关联的工作表对象的名称。



您可以在。


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.

Function MySheet()
    Select Case TypeName(Application.Caller)
        Case "Range"
            MySheet = Application.Caller.Parent.Name
        Case "String"
            MySheet = Application.Caller
        Case "Error"
            MySheet = "Error"
        Case Else
            MySheet = "unknown"
    End Select
End Function

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).

这篇关于Application.Caller对象需要错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 18:00