VBA-语法-Type结构体

VBA中结构体不能定义在函数或者过程中,要定义在模块中,否则会提示无效内部过程,或者类型未定义

定义:

Type Person
  pName As String
  pAge As Byte
End Type

使用:

Dim udtPerson As Person
With udtPerson
  .pName = "老五"
  .pAge = 55
End With

在数组中使用:

Dim udtUserInfo(1 To 2) As Person
  With udtUserInfo(1)
  .pName = "老五"
  .pAge = 55
End With
Dim abc As Person
MsgBox abc.pName 这样是正确的
MsgBox abc 这样会编译报错

 


————————————————

原文链接:https://blog.csdn.net/weixin_42108319/article/details/99824530

posted @ 2022-12-07 20:26  vba是最好的语言  阅读(414)  评论(0)    收藏  举报