How to pass multiple arguments to procedure in VBA?

excel, vba

Solution

You need to remove the brackets

callByValue s1, s2

Also remember in VBA, When you say `Dim s1, s2 As String` only `s2` will be declared as `String` and the first one will be declared as `Variant`

One more thing that I noticed was that you didn't assign the values of `s1` and `s2` before calling the sub. You will get a blank for both.

For example, do this.

Sub Sample()
    Dim s1 As String, s2 As String
    s1 = "Blah": s2 = "Blah Blah"
    callByValue s1, s2
End Sub

Problem

I am trying to pass two string parameters to a Sub, but its not allowing me do that. The approach I have used is given below. ``` Sub callByValue( str1 As String, str2 As String) MsgBox str1 MsgBox str2 End Sub ``` Calling Macros: ``` Dim s1, s2 As String callByValue(s1,s2) ``` While calling `callByvalue`, it's throwing a compiler error.

Original source

Related problems