从另一个工作表中识别所单击形状的名称

时间:2017-08-07 23:08:15

标签: excel-vba shape vba excel

我在第1页和第2页上工作,在两张工作表中都有包含代码的形状。表1中的形状ID是“RUN 1”,而表2中的形状ID是“EQ-1”。我已经有一个代码可以识别我在sheet1 / sheet2上单击的形状ID。但是代码是调试的,解释为“找不到具有指定名称的项目”。谢谢。请帮忙 :) 此代码必须位于工作表2

sub x ()

'the first trial
If Sheet1.Shapes(Application.Caller).Name = "RUN 1" Then Sheet2.Cells(1, 2) = "x"
If activesheet.Shapes(Application.Caller).Name = "EQ-1" Then Sheet2.Cells(1, 2) = "x"

'the second trial
If Sheet1.Shapes(Application.Caller).Name = "RUN 1" Or _
activesheet.Shapes(Application.Caller).Name = "EQ-1" Then Sheet2.Cells(1, 2) = "x"

end sub 

1 个答案:

答案 0 :(得分:0)

...试

Sub x()

    If Application.Caller = "RUN 1" Or Application.Caller = "EQ-1" Then
        Sheet2.Cells(1, 2) = "x"
    End If

End Sub

希望这有帮助!