尝试做一些简单的事情,将当前选定的单元格保存到范围变量中。选择单个单元格。
Function SelectionInfo() As Range
SelectionInfo = Selection
Debug.Print "SelectionInfo " + SelectionInfo.Address
SelectionInfo.Select
End Function
但是我在函数的第1行出现错误"运行时错误91,对象变量或没有设置块变量"
答案 0 :(得分:0)
让我们使用 sub 而不是功能
Sub SelectionInfo()
Dim s As String
s = TypeName(Selection)
MsgBox s
If s = "Range" Then MsgBox Selection.Address
If s = "Shape" Then MsgBox Selection.Name
If s = "ChartArea" Then MsgBox Selection.Name
End Sub