关于vba:如何在一行中声明和定义自定义类型的变量

How do i declare and define a variable of a custom type in one line

如何在一行中声明和设置自定义类型。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Option Explicit

Type Stackoverflow
    stack As String
    overflow As String
End Type

Sub WorkingExample()
    Dim example As Stackoverflow
    example.stack ="stack"
    example.overflow ="overflow"
    MsgBox (example.stack + example.overflow)
End Sub

Sub NotCompiling()
    Dim example As Stackoverflow = {.stack ="stack", .overflow ="overflow"}
    MsgBox (example.stack + example.overflow)
End Sub

在这个迷你示例中,WorkingExample显示了我想要的行为,而NotCompiling部分显示了我想写的内容,但我却不能。

请说明如何将此Dim example As Stackoverflow = {.stack ="stack", .overflow ="overflow"}之类的内容写成一行。


冒号是一条以回车符结尾的行。

1
Sub WorkingExample():Dim example As Stackoverflow:example.stack ="stack":example.overflow ="overflow":MsgBox (example.stack + example.overflow):End Sub