1

Just regarding passing arguments in vba, ByRef seems to act differently if the argument is passed in parenthesis rather than explicitly stating them using ':=' for example:

Sub CallingProcedure()
    Dim a As Long
    a = 123
    CalledProcedure (a)
    MsgBox (a)
    CalledProcedure x:=a
    MsgBox (a)
End Sub

Sub CalledProcedure(ByRef x As Long)
    x = 321
End Sub

The first MessageBox will show 123, while the second will show 321. I can't find anywhere explaining why there is a difference in passing the arguments in parenthesis or with ':=". Does anyone know why?

Tom Malkin
  • 2,134
  • 2
  • 19
  • 35

0 Answers0