我试图在单词VBA中使用userforms将未定义数量的变量保存到一个数组中,以便稍后在文档中输入但是我无法使增量计数器工作,它只会保存最后一次输入,它被保存为输入0.
Public i As Integer
Sub Macro6()
UF1.Show
End Sub
Private Sub btnAddC_Click()
Dim CName(100) As String
Dim CAddress(100) As String
CName(i) = txtName.Text
CAddress(i) = txtAddress.Text
i = i + 1
Unload Me
UF1.Show
End Sub
Private Sub btnNext_Click()
Dim CName(100) As String
Dim CAddress(100) As String
Dim n As Integer
CName(i) = txtName.Text
CAddress(i) = txtAddress.Text
Unload Me
For n = 0 To i
Selection.TypeText Text:="Client number " & n & " is " & CName(n) & "."
Selection.TypeParagraph
Selection.TypeText Text:="Client number " & n & " is " & CAddress(n) & "."
Selection.TypeParagraph
Next
End Sub
Private Sub UserForm_Initialize()
txtName.Text = ""
txtAddress.Text = ""
End Sub
输出始终为:
客户编号0是a。 客户编号0是b。