Hi All;
Is there a way to pass a var from one excel doc macro to another and then change the var and return the new var into the original macro?
Here is what I have so far. The calling_macro correctly opens the SANDBOX - Macro from Macro - Source.xlsm file, passes bob="hi" to the msg_box macro.
The msg_box macro updates var bob to equal "ten".
When the macro returns to the calling_macro, bob does not update to equal "ten" but stays as "hi" instead of returning "ten".
Code for calling_macro in document 1:
SANDBOX - Macro from Macro - Source.xlsm (document 2) and macro msg_box code
I have looked into ByRef, but it doesn't return the updated value back to the original document. It will pass it to another document / macro though. I'd like to avoid chaining macros together instead of returning the updated var to the original macro.
Here is the reference article for ByRef Link
Thanks for the assistance.
Mike
Is there a way to pass a var from one excel doc macro to another and then change the var and return the new var into the original macro?
Here is what I have so far. The calling_macro correctly opens the SANDBOX - Macro from Macro - Source.xlsm file, passes bob="hi" to the msg_box macro.
The msg_box macro updates var bob to equal "ten".
When the macro returns to the calling_macro, bob does not update to equal "ten" but stays as "hi" instead of returning "ten".
Code for calling_macro in document 1:
Code:
Sub calling_macro()
Dim bob As String
bob = "hi"
Workbooks.Open ("C:\DUMMY FOLDER\SANDBOX - Macro from Macro - Source.xlsm"), ReadOnly:=True
Application.Run "'SANDBOX - Macro from Macro - Source.xlsm'!thisworkbook.msg_box", bob
MsgBox bob
End Sub
SANDBOX - Macro from Macro - Source.xlsm (document 2) and macro msg_box code
Code:
Sub msg_box(bob)
MsgBox "Hello world"
bob = "ten"
End Sub
I have looked into ByRef, but it doesn't return the updated value back to the original document. It will pass it to another document / macro though. I'd like to avoid chaining macros together instead of returning the updated var to the original macro.
Here is the reference article for ByRef Link
Thanks for the assistance.
Mike