我想从 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
最佳答案
尝试这个
Function GetName() As fullName
Dim temp As fullName
temp.FirstName = "John"
temp.LastName = "Doe"
With temp
GetName.FirstName = .FirstName
GetName.LastName = .LastName
End With
End Function
但是
GetName = temp
应该也可以工作
关于excel - 如何从 VBA 函数返回自定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57323491/