如何将表单的TextBox
对象传递给方法?
以下代码发出异常.
Private Sub DoSmthWithTextBox(ByRef txtBox as TextBox) txtBox.BackColor = vbRed End Sub Private Sub TextBox1_Change() DoSmthWithTextBox Me.TextBox1 End Sub
DoSmthWithTextBox Me.TextBox1
传递String
from TextBox1
而不是对象引用时会出现问题.
如何将TextBox
对象传递给DoSmthWithTextBox
方法?
重写Excel:
Private Sub DoSmthWithTextBox(txtBox As MSForms.TextBox) txtBox.BackColor = vbRed End Sub
据我所知,这是因为Excel有一个形状的对象文本框,而userforms使用ActiveX控件文本框,因此您需要显式引用MSForms库.