【发布时间】:2019-08-02 09:20:02
【问题描述】:
我想从 VBA 函数返回自定义类型。当我运行以下代码时,我收到错误“第 16 行错误 - 类型不匹配”。我真的不明白出了什么问题。
Type FullName
FirstName As String
LastName As String
End Type
Sub Main
Dim fullName As FullName
fullName = GetName()
MsgBox fullName.FirstName &" "& fullName.LastName
End Sub
Function GetName() As FullName
Dim temp As FullName
temp.FirstName = "John"
temp.LastName = "Doe"
Set GetName = temp
End Function
【问题讨论】:
-
你可以试试 [GetName = temp] 而不是 [Set GetName = temp]
-
我试过了,结果一样
-
我打开了一个新的 Excel,创建了一个新的模块,粘贴了您的代码,并检查了它是否失败。然后退出“设置”。它运行正常。
-
好的,我在 Rumba 脚本引擎中运行它。所以也许这就是问题