Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,779
- Office Version
- 2016
- Platform
- Windows
Hi all,
As you know, when passing an argument ByRef the Callee procedure code can change the value underlying the argument in the calling code as shown in the following example :
The above MsgBox returns 2 as expected instead of 1 because the Callee procedure changed the value of the passed argument
However, if we use Application.Run, the above mechanism no longer works and the passed argument is not modified despite using ByRef... (In the following example, the MsgBox now returns 1 instead of 2)
Does anybody know if there is a way of making the ByRef work with Application.run ?
As you know, when passing an argument ByRef the Callee procedure code can change the value underlying the argument in the calling code as shown in the following example :
Code:
Sub Caller1()
Dim X As Long
X = 1
Call Callee(X)
MsgBox X [COLOR=#008000][B]' returns 2[/B][/COLOR]
End Sub
Sub Callee(ByRef arg As Long)
arg = 2
End Sub
The above MsgBox returns 2 as expected instead of 1 because the Callee procedure changed the value of the passed argument
However, if we use Application.Run, the above mechanism no longer works and the passed argument is not modified despite using ByRef... (In the following example, the MsgBox now returns 1 instead of 2)
Code:
Sub Caller2()
Dim X As Long
X = 1
Application.Run "Callee", X
MsgBox X [B][COLOR=#008000]' returns 1[/COLOR][/B]
End Sub
Sub Callee(ByRef arg As Long)
arg = 2
End Sub
Does anybody know if there is a way of making the ByRef work with Application.run ?