Thanks in advance for any help...
I'm creating a frontend form for a spreadsheet which uses a lot of
textboxes. I want to be able to pass any of these textbox objects to a
function which will alter the object's properties.
A simplified version of the code is shown below:
Private Sub TextBox1_Change()
Call makeRed(TextBox1) 'this gives error 13
End Sub
Private Sub TextBox2_Change()
Call makeRed(TextBox2) 'this gives error 13
End Sub
Private Sub makeRed(ByRef tb As TextBox)
tb.BackColor = vbRed
End Sub
I can get this to work using Visual Basic 5. But running it with VBA for Excel 97 I get:
Run-time error '13':
Type mismatch
It seems the TextBox's default value is being passed to the function, but I want the object itself. (Note this problem also happens in Visual Basic 5 if I don't use Call when calling the function).
How can this be done in VBA for Excel ? I've googled for answers but so far
drawn a blank.
I'm creating a frontend form for a spreadsheet which uses a lot of
textboxes. I want to be able to pass any of these textbox objects to a
function which will alter the object's properties.
A simplified version of the code is shown below:
Private Sub TextBox1_Change()
Call makeRed(TextBox1) 'this gives error 13
End Sub
Private Sub TextBox2_Change()
Call makeRed(TextBox2) 'this gives error 13
End Sub
Private Sub makeRed(ByRef tb As TextBox)
tb.BackColor = vbRed
End Sub
I can get this to work using Visual Basic 5. But running it with VBA for Excel 97 I get:
Run-time error '13':
Type mismatch
It seems the TextBox's default value is being passed to the function, but I want the object itself. (Note this problem also happens in Visual Basic 5 if I don't use Call when calling the function).
How can this be done in VBA for Excel ? I've googled for answers but so far
drawn a blank.