VBA Geniuses:
Question 1: Is it possible to set the .OnAction value of a menu option to a Public Sub which is in ThisWorkbook or must the sub be in a module?
This works: ViewTextFile() is a public sub in a module
.Controls(strMenuItem).OnAction = "'ViewTextFile """ & strMenuItem & """'"
I would like to move the sub to ThisWorkbook, so the value becomes something like this:
.Controls(strMenuItem).OnAction = "'" & ThisWorkbook.Name & "!ViewTextFile """ & strMenuItem & """'"
Question 2: If the answer to #1 is yes, then what is the syntax for getting the reference to “ThisWorkbook” into the .OnAction command?
Note that the parameter strMenuItem must be included in the value (as in, “ViewTextFile my_file.txt”). I have tried many variations of the above but no success.
Thank you, VBA geniuses!
1 Answer