Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, add "
ByVal" (without quotation marks) to the argument receiving the
ParamArray in the function that is being called.
For example, the following macro code returns an error when you run the
Test subroutine:
Sub Test()
x = myfun(1)
MsgBox x
End Sub
Function myfun(y As Integer, ParamArray myarr() As Variant) As Integer
myfun = otherfun(y, myarr)
End Function
Function otherfun(y As Integer, myarr As Variant) As Integer
otherfun = y * 2
End Function
If you change the
otherfun function declaration to
Function otherfun(y As Integer, ByVal myarr As Variant) As Integer
and run the "Test" subroutine, you get a message box with a value of 2
displayed in it.