tags:

views:

7

answers:

1

Hello there. I've been fiddling with Excel VBA for some time, but I never had any formal training whatsoever. I have the following piece of code on a XLSM module :

Public Type ks_solution
    W As Integer
    NF As String
    ID As Integer
End Type

Public Sub MySub()
    //does some things
    MyKSSolution = MyFunction(params)
End Sub

Public Function MyFunction(params) as ks_solution
    //does stuff and returns a ks_solution
End Function

When I try to run the code, VBA compiler returns a "Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions" error.

Any help would be greatly appreciated.

--Yuri

A: 

Er, nevermind. Looks like the problem was in the var declarations.

I thought

Dim v1, v2 as ks_solution

was the same as

Dim v1 as ks_solution, v2 as ks_solution

but apparently, it isn't. In the first case, v1 gets declared as a Variant. Sorry to take your time.

Yuri