textbox trouble

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

Hello agian!

I'm trying to set a textbox for use later in the code.

Dim iBox as Textbox

if varTest = 1 then
Set iBox = Sheet1.textbox1
elseif varTest = 2 then
Set iBox = Sheet1.textbox2
elseif varTest = 3 then
Set iBox = Sheet1.textbox3
end if

with iBox
.text = "Test"
.enabled=False
etc...
end with

It errors during the Set iBox= line of codes, what am I doing wrong?

Thanks
Craig
 
Try

If varTest = 1 Then
Set iBox = Sheets("Sheet1").TextBox1
etc

Hope this helps
Rowan
 
You may declare iBox as wrong Object type.

Try:

Dim iBox as msforms.TextBox
 
Hi Craig,

If the textboxes are from the control Toolbox, try something like:

..===========================>>
Sub TestIt()
Dim VarTest As Long
Dim iBox As OLEObject

'code to assign value to VarTest variable, e.g.:
VarTest = 2

Set iBox = Sheets("Sheet1").OLEObjects("textbox" & VarTest)

With iBox.Object
.Text = "Test"
.Enabled = False
End With

End Sub
'<<===========================
 
Hi Craig! You can also just declare iBox as Object...

Dim iBox as Object
...
Set iBox = Sheet1.TextBox1
...
 
Yes... Thanks, I did declare it as an Object.... then all worked fine! You'd
figure if it was a TextBox you'd declare it as a Textbox! Go Figure!
Thanks Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top