+ Reply to Thread
Results 1 to 5 of 5

Cycling through controls in worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2004
    Posts
    3

    Cycling through controls in worksheet

    Can someone tell me how to cycle through all the controls in a worksheet? I tried this:

    Private Sub CommandButton1_Click()
    Dim ctrl As Control
    Dim blad As Worksheet
    
    For Each blad In ActiveWorkbook.Worksheets
        Debug.Print blad.Name
        For Each ctrl In Controls
            Debug.Print ctrl.Name
        Next ctrl
    Next blad
    
    End Sub
    But this resulted in an "object required" error. Apparently the worksheet object does not have a controls collection.

  2. #2
    Registered User
    Join Date
    08-11-2005
    Location
    Netherlands Waddinxveen
    Posts
    81
    Private Sub CommandButton1_Click()
    Dim ctrl As Control
    Dim blad As Worksheet
    
    For Each blad In ActiveWorkbook.Worksheets
        Debug.Print blad.Name
        For Each ctrl In Controls        'The controls of which object?
                                                      'als je blad bedoelt dan wordt het Blad.Controls 
            Debug.Print ctrl.Name
        Next ctrl
    Next blad
    
    End Sub

  3. #3
    Ron de Bruin
    Guest

    Re: Cycling through controls in worksheet

    Hi DeeJay

    You can use the Shapes collection

    I have info about deleting controls here, but you can see how you must loop there
    http://www.rondebruin.nl/controlsobjectsworksheet.htm



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "DeeJay" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Can someone tell me how to cycle through all the controls in a
    > worksheet? I tried this:
    >
    >
    > Code:
    > --------------------
    > Private Sub CommandButton1_Click()
    > Dim ctrl As Control
    > Dim blad As Worksheet
    >
    > For Each blad In ActiveWorkbook.Worksheets
    > Debug.Print blad.Name
    > For Each ctrl In Controls
    > Debug.Print ctrl.Name
    > Next ctrl
    > Next blad
    >
    > End Sub
    > --------------------
    >
    >
    > But this resulted in an "object required" error. Apparently the
    > worksheet object does not have a controls collection.
    >
    >
    > --
    > DeeJay
    > ------------------------------------------------------------------------
    > DeeJay's Profile: http://www.excelforum.com/member.php...fo&userid=5420
    > View this thread: http://www.excelforum.com/showthread...hreadid=397561
    >




  4. #4
    Registered User
    Join Date
    01-26-2004
    Posts
    3
    How can I see what type my control is? I am using comboboxes but I'd like to know it for other controls as well.

  5. #5
    Registered User
    Join Date
    01-26-2004
    Posts
    3
    Never mind. I used this:

    Sub OLEObjects3()
    'Delete/hide only all CommandButtons or ComboBoxes or ??? from the Control Toolbox
        Dim obj As OLEObject
        For Each obj In ActiveSheet.OLEObjects
            If TypeOf obj.Object Is MSForms.CommandButton Then
                obj.Delete
                ' or obj.Visible = False if you want to hide them
            End If
        Next
    End Sub
    And it works!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1