例如,UserForm1中有三個控件,Label1,Label2,TextBox1
那麽,我們可以這樣表示:
a = 1 : b = 2
UserForm1.Controls("Label" & a).Caption 表示Label1.Caption
UserForm1.Controls("Label" & b).Caption 表示Label2.Caption
UserForm1.Controls("TextBox" & a).Text 表示TextBox1.Text
如果妳的控件位於工作表中,那麽我們可以使用OleObjects集合來表示指定的控件,
例如,Sheet1工作表中有三個控件,Label1,Label2,CommandButton1
a = 1 : b = 2
那麽我們可以這樣表示,註意Object不可省略:
Sheet1.OleObjects("Label" & a).Object.Caption 表示Label1.Caption
Sheet1.OleObjects("Label" & b).Object.Caption 表示Label2.Caption
Sheet1.OleObjects("CommandButton" & a).Object.Caption 表示CommandButton1.Caption