Excel VBA - 将按钮标题传递给按钮单击

时间:2013-11-05 17:32:41

标签: excel vba excel-vba

我目前有一张电子表格,可以使用下面的方法创建和销毁许多按钮。 123456表示我想使用“VIEW_SO”

查找的销售订单
Dim btn As Button
Set btn = ws.Buttons.Add(cell.left, cell.top , cell.width, cell.height)
With btn
    .OnAction = "VIEW_SO"
    .caption = "SO=123456"
    .name = "SO123456"
End With

这很有效。问题在于我希望VIEW_SO根据销售数量改变其行为。有没有办法在例程中获取按钮名称或标题?以下是我想要做的事情:

Public Sub View_SO (CAPTION as String)
    'I need to extract 123456 based on which button exists and pass 
    '   it to the subroutine
    v = split(CAPTION,"=",2)
    'Go do stuff with v(1)

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

Application.Caller会为您提供按钮的名称