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
My开发者_如何学编程KSSolution = 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
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.
精彩评论