好吧,我的问题是我创建了一个VBA Sub,它接收一个excel Cell引用和2个文本值以及一个Variant作为参数.
Sub CreateButton(oCell, sLabel, sOnClickMacro, oParameters)
Run Code Online (Sandbox Code Playgroud)
这个Sub成功地在oCell上创建了一个按钮但是我必须向Macro发送一个参数,实现它的最佳方法是什么?
如果已经挖掘了一些不起作用的方法,而另一些方法也很脏,这些都不会让我填饱肚子
在我帮助解决问题的帮助下,我在这里提出了一个更简单的工作解决方案
Sub Button_Click(sText)
MsgBox "Message: " & sText
End Sub
Sub Test_Initiallize()
Dim oCell
Dim oSheet
Dim oShape
Set oCell = Range("A1")
Set oSheet = ThisWorkbook.Sheets(1)
For Each oShape In oSheet.Shapes
oShape.Delete
Next
Set oShape = oSheet.Shapes.AddShape(msoShapeRectangle, oCell.Left, oCell.Top, oCell.Width, oCell.Height)
oShape.TextFrame.Characters.Text = "Click Me"
oShape.OnAction = "'Button_Click ""Hello World""'"
End Sub
Run Code Online (Sandbox Code Playgroud)