Home » excel » excel vba – ByRef arugement type mismatch VBA Discussion

excel vba – ByRef arugement type mismatch VBA Discussion

Posted by: admin May 14, 2020 Leave a comment


I am writing a method in VBA and I received a ByRef argument type mismatch. After doing some research I found a quick fix–store my value in another variable and then pass that new variable into my method. Can anyone explain to me the method behind the madness? What is going on under the hood in VBA? Why will it not accept my original variable?


For Each excl In excelFiles
    Dim temp As String
    temp = excl
    Call uploadExcelFile(temp, schema)
Next excl

Method used:

Private Sub uploadExcelFile(excelWb As String, schema As Worksheet)

excelFiles is an Array of Strings. Please let me know if you guys would like anymore info. Excited to learn what is going on here.

How to&Answers:

Even though you’re looping through a string array, the VBA for-each loop expects a variant as the loop “counter” (excl in your case).

You can use

Call uploadExcelFile(Cstr(excl), schema)

to avoid that intermediate temp variable.