Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Variable in Object Name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gojavid - 29 Jun 2007 15:58 GMT
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!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.