Not possible to pass UDT between modules on different projects

90 Views Asked by At

I believe that what I'm about to ask is a restriction but I am hopeful that there is a satisfactory solution.

I am working with multiple files / workbooks and am intending to keep code associated with the data as much as possible. Therefore I want to be able to link from one procedure to another across projects.

I would like to be able to pass my arguments in a user-defined type when linking but have come up the following compiler error:

Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions

What I've found is that I only get this problem when I use Application.Run not when I issue a Call statement. However, I could not get Call to work across projects. Subsequent reading seems to confirm this. (I did read that Application.Run does not pass ByRef and it is also evident that UDT's can only pass ByRef). So it seems I'm lumbered. Here is some sample code to illustrate the point

Option Explicit

Public Type type1
  s As String
End Type

Public Sub main()

Dim t As type1

Application.Run "Book2!Freda", t

End Sub

Application.Run "Book2!Freda", t is where the compiler error occurs

0

There are 0 best solutions below