从用户表单中动态提取文本

Dynamically extract text from a userform

我想从用户窗体的文本框中提取文本并将它们作为元素存储在数组中。但是,这些文本框具有动态名称,我无法设置数组元素,因为它将它们存储为字符串。

'Loop through the sections to fill the array using a concatonated dynamic path
For Counter = 0 To numSections - 1

    'Fill in title, start page, end page
    sectionInfo(Counter, 0) = "UserForm1.TextInput" & CStr(Counter) & ".Text"

    sectionInfo(Counter, 1) = "UserForm1.pageStart" & CStr(Counter) & ".Text"

    sectionInfo(Counter, 2) = "UserForm1.pageEnd" & CStr(Counter) & ".Text"

Next Counter

如何连接字符串并将其作为命令而不是字符串传递?我开始认为这是不可能的,因为我到处都看过。

使用Controls collection。像 UserForm1.Controls("TextInput" & CStr(Counter)).Text 等等。

'Loop through the sections to fill the array using a concatonated dynamic path
For Counter = 0 To numSections - 1
    'Fill in title, start page, end page
    sectionInfo(Counter, 0) = UserForm1.Controls("TextInput" & CStr(Counter)).Text
    sectionInfo(Counter, 1) = UserForm1.Controls("pageStart" & CStr(Counter)).Text
    sectionInfo(Counter, 2) = UserForm1.Controls("pageEnd" & CStr(Counter)).Text
Next Counter