'VBA Pass argument with .Onaction with parameter
I've read other articles on this topic and their proposed solution is not working for me:
Sub doStuff()
Dim x As String
x = "hello"
Sheets("sheet2").Shapes(1).OnAction = "'testIt " & x & "'"
End Sub
Sub testIt(something As String)
End Sub
When I click on Shapes(1) in sheet2, I get the following error response:
Cannot run macro "testIt hello". The macro may not be available in this workbook or all macros may be disabled
I've tested this with other code that does not require a parameter, and it worked. It would simply read something like: Sheets("sheet2").Shapes(1).OnAction = "someOtherMacro"
Solution 1:[1]
Needs quotes around the argument:
Sheets("sheet2").Shapes(1).OnAction = "'testIt """ & x & """'"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tim Williams |
