我有下面的VBA脚本来创建二维文本框数组,但是在某些行和列的组合上无法正常工作。不断更改列号和行号,然后查看问题。感谢任何解决它的建议。我复制了以下内容,并希望可以。
显式选项 子MakeUserForm() 将MyUserForm调暗为VBComponent Dim N,X,i,j,row,col,tp,lft为整数,MaxWidth为长 昏暗的NewTextBox()作为MSForms.TextBox col = 6 行= 4 ReDim NewTextBox(1到col,1到行)
'//Make a userform
Set MyUserForm = ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
With MyUserForm
.Properties("Height") = 200
.Properties("Width") = 600
On Error Resume Next
.Name = "NewForm"
.Properties("Caption") = "User form " + "Col = " + CStr(col) + " Row = " + CStr(row)
End With
'//Add two dimensional TextBox array to the form
tp = 30
For i = 1 To row
lft = 10
For j = 1 To col
Set NewTextBox(i, j) = MyUserForm.Designer.Controls.Add("forms.TextBox.1")
With NewTextBox(i, j)
.Name = "TextBox" + CStr(i) + CStr(j)
.Height = 16
.Width = 44
.Left = lft
.Top = tp
End With
lft = lft + 45
Next j
tp = tp + 18
Next i
ShowForm
结束子
Sub ShowForm() 新建表格 结束