因此,我目前正在尝试创建一个通用变量,该变量将根据用户表单“时间轴”的文本框和标签循环更改值。 TimeLineBox是我要根据Num或Number值更改的通用文本框值。
不幸的是,它告诉我我需要一个对象,然后将它们设置为文本框并添加标签时,它表示该对象尚未设置。
TimelineBox1 = Timeline.TextBox1.Value
TimelineBox2 = Timeline.TextBox2.Value
TimeLineBox3 = Timeline.TextBox3.Value
TimeLineBox4 = Timeline.TextBox4.Value
TimeLineBox5 = Timeline.TextBox5.Value
TimeLineBox6 = Timeline.TextBox6.Value
TimeLineBox7 = Timeline.TextBox7.Value
TimeLineBox8 = Timeline.TextBox8.Value
TimeLineBox9 = Timeline.TextBox9.Value
TimelineLabel1 = Timeline.Label1.Caption
TimelineLabel2 = Timeline.Label2.Caption
TimeLineLabel3 = Timeline.Label3.Caption
TimeLineLabel4 = Timeline.Label4.Caption
TimeLineLabel5 = Timeline.Label5.Caption
TimeLineLabel6 = Timeline.Label6.Caption
TimeLineLabel7 = Timeline.Label7.Caption
TimeLineLabel8 = Timeline.Label8.Caption
TimeLineLabel9 = Timeline.Label9.Caption
Do While Num < 10
Dim TimelineBox As TextBox
Dim TimelineLabel As Label
TimelineBox = "TimelineBox" & Num
TimelineLabel = "TimelineLabel" & Num
MSNum = "MS" & Num1
MSName = "MS" & Num1
If TimelineBox.Value <> "" Then
MSNum = TimelineBox1.Value
MSName = TimelineLabel1.Value
Num1 = Num1 + 1
End If
Num = Num + 1
Loop
答案 0 :(得分:1)
使用Textbox
对象,您需要使用关键字set。
最重要的是,您似乎试图将其设置为等于String
。
如果您需要循环控件,则可以尝试循环使用用户窗体中的所有控件:
Dim Ctrl As MSForms.Control
For Each Ctrl In Form.Controls
If TypeName(Ctrl) = "TextBox" then
'... Do something with your textbox control
End If
Next Ctrl