FractalWalk
Technical User
I think I know the answer to this question but I hoping someone here can confirm or deny. I have an Excel add-in that stores macros that I am using to call from other open workbooks. I am using Application.Run to call them and they work in general with the exception being when I pass a variable and need the modified result returned. Hypothetical example:
If I place both macros in the same workbook and run "Test", I get the result I expect: a message box displays the value 2. But when I place the Test_Math routine in the Add-in and reference it with Application run, the value displayed is 1. When I de-bug the add-in code, I have confirmed that it is receiving the variable and it is indeed converting it to a value of 2, it just doesn't pass it back. I know that if I convert the code to a function that it works, but due to the manner and number of times I have already utilized the routine, it would be quite cumbersome to do that.
So my question is, is there a way to pass a variable to a macro in an outside workbook and receive the altered variable back?
Code:
Global n as integer
Sub Test()
n = 1
Application.Run "Test_Math", n
MsgBox (n)
End Sub
Sub Test_Math(x)
x = x * 2
End Sub
If I place both macros in the same workbook and run "Test", I get the result I expect: a message box displays the value 2. But when I place the Test_Math routine in the Add-in and reference it with Application run, the value displayed is 1. When I de-bug the add-in code, I have confirmed that it is receiving the variable and it is indeed converting it to a value of 2, it just doesn't pass it back. I know that if I convert the code to a function that it works, but due to the manner and number of times I have already utilized the routine, it would be quite cumbersome to do that.
So my question is, is there a way to pass a variable to a macro in an outside workbook and receive the altered variable back?