Good morning all,
I have some code that uses a variable in a object name.
Actually, it doesn't use it yet, but I'd like it to. I have the
following code that I've tried in several different variations, but I
haven't been able to get it to work.
Code:
If Worksheets("patient data").Range("C20") <> "" Then
pd = 14
ElseIf Worksheets("patient data").Range("C19") <> "" Then
pd = 13
End if
tx_box = "Textbox" & pd
For ot = 1 To pd
With tx_box
.Enabled = True
.Visible = True
End With
Next ot
Any ideas?
Dave Peterson - 29 Jun 2007 17:32 GMT
I'm not quite sure what you're doing, but maybe one of these will give you an
idea:
'just a single textbox from the control toolbox toolbar:
Option Explicit
Sub testme()
Dim OLEObj As OLEObject
Dim iCtr As Long
iCtr = 1
Set OLEObj = Nothing
On Error Resume Next
Set OLEObj = Worksheets("sheet1").OLEObjects("TextBox" & iCtr)
On Error GoTo 0
If OLEObj Is Nothing Then
'not a valid name!
Else
OLEObj.Visible = True
OLEObj.Enabled = True
End If
End Sub
'looping through a bunch of textboxes from the control toolbox toolbar:
Option Explicit
Sub testme2()
Dim OLEObj As OLEObject
Dim iCtr As Long
iCtr = 1
For iCtr = 1 To 3
Set OLEObj = Nothing
On Error Resume Next
Set OLEObj = Worksheets("sheet1").OLEObjects("TextBox" & iCtr)
On Error GoTo 0
If OLEObj Is Nothing Then
'not a valid name!
Else
OLEObj.Visible = True
OLEObj.Enabled = True
End If
Next iCtr
End Sub
> Good morning all,
> I have some code that uses a variable in a object name.
[quoted text clipped - 20 lines]
>
> Any ideas?

Signature
Dave Peterson
Gojavid - 29 Jun 2007 17:58 GMT
I appreciate your help Dave!