如何在不使用Application.Caller
的情况下检索单击以运行宏的形状?它的名称或形状本身就是一个对象。
我无法使用Application.Caller
,因为如果形状名称大于30个字符,则只检索前30个字符。
也许有一个API可以检索Sape对象?
修改
由于
答案 0 :(得分:2)
您可以重命名工作表中的Shape对象吗?
Private Sub Workbook_Open()
Dim shp As shape
Dim i As Integer
For Each shp In ThisWorkbook.Sheets(1).Shapes
shp.Name = "Shape" & Format(i, "0000")
i = i + 1
Next shp
End Sub
或者,您可以手动设置每个形状的.OnAction属性,以将形状名称传递给您的函数:
Sub RenameShapes2()
Dim shp As shape
Dim i As Integer
For Each shp In ThisWorkbook.Sheets(1).Shapes
shp.name = "Shape" & "abcdefghijklmnopqrstuvwxyz0123456789_" & Format(i, "0000")
shp.OnAction = "'userFunction """ & shp.name & """'"
i = i + 1
Next shp
End Sub
Sub userFunction(name As String)
MsgBox name
End Sub
这允许您使Shape长度超过30个字符。
虽然有点难看