I want to pass my set of objects and variables to VBA function, make some changes to it and pass it back as a result. So I create a sample Class1:
Public pInfo As String
and sample function:
Public Function populate(someVar As Class1) As Class1
populate.pInfo = someVar.pInfo & " 1 "
End Function
and tryed to pass it to my function populate:
Sub test()
Dim v, w As Class1
Set v = New Class1
v.pInfo = "303"
Set w = populate(v) ' ERROR here
End Sub
results in compile error : byRef argument type mismatch.
UPDATE. Thanks to your help it compiles now.
Its a type error
Unintuitively here only
wis of typeClass1,vis a variant.To make them both
Class1you must:Here:
populateis not an instance ofClass1, you need to create it:(Rather than using a function you may prefer a
v.copyTo(w))