小编典典

我可以同时在 VBA 中声明和分配一个变量吗?

all

我是 VBA 新手,想知道是否可以将以下声明和赋值转换为一行:

Dim clientToTest As String
clientToTest = clientsToTest(i)

或者

Dim clientString As Variant
clientString = Split(clientToTest)

阅读 139

收藏
2022-07-31

共1个答案

小编典典

不幸的是,VBA 中没有速记,:如果您希望将连续字符放在一行中以提高可读性,那么您将得到的最接近的是纯视觉的东西;

Dim clientToTest As String:  clientToTest = clientsToTest(i)
Dim clientString As Variant: clientString = Split(clientToTest)

提示(其他答案/评论的摘要):也适用于对象(Excel 2010):

Dim ws  As Worksheet: Set ws = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As New Worksheet: ws2.Name = "test"
2022-07-31