Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cycling through controls in worksheet


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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" wrote in message
...

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cycling through controls in worksheet


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 'The controls of which object?
'als je blad bedoelt dan wordt het Blad.Controls
Debug.Print ctrl.Name
Next ctrl
Next blad

End Su
-------------------

--
Dnere
-----------------------------------------------------------------------
Dnereb's Profile: http://www.excelforum.com/member.php...fo&userid=2618
View this thread: http://www.excelforum.com/showthread.php?threadid=39756

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cycling through controls in worksheet


How can I see what type my control is? I am using comboboxes but I'
like to know it for other controls as well

--
DeeJa
-----------------------------------------------------------------------
DeeJay's Profile: http://www.excelforum.com/member.php...nfo&userid=542
View this thread: http://www.excelforum.com/showthread.php?threadid=39756

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cycling through controls in worksheet


Never mind. I used this:


Code
-------------------
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 Su
-------------------


And it works

--
DeeJa
-----------------------------------------------------------------------
DeeJay's Profile: http://www.excelforum.com/member.php...nfo&userid=542
View this thread: http://www.excelforum.com/showthread.php?threadid=39756

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls in a Worksheet Jeff Excel Programming 4 July 11th 05 11:59 PM
Controls on worksheet gr8guy Excel Programming 1 May 1st 04 03:11 AM
controls on worksheet jim c. Excel Programming 3 February 9th 04 06:43 PM
Worksheet Controls Andrew Arthur Excel Programming 0 February 5th 04 06:46 PM
Referencing to controls on a worksheet John Nikolopoulos Excel Programming 3 September 10th 03 10:08 AM


All times are GMT +1. The time now is 10:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"