|
-
Feb 13th, 2009, 01:14 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Looping through controls
I'm sure this has been asked many a time, and I'm sure for what is probably a repeat post, but after much attempt I'm still failing at simply looping through all the controls on my form and outputting the name and caption of that object if it is an optionButton, Frame, CheckBox, or Label.
I currently have the code just for frame looking like this...
vb Code:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is OptionButton Then
MsgBox (ctl.Caption)
End If
Next ctl
This loop appears to iterate but never see a msgbox... The above code works for a frame, but not for option buttons.... Any help would be appreciated! thanks!
-
Feb 13th, 2009, 01:48 PM
#2
Re: Looping through controls
Try this
Code:
Private Sub CommandButton1_Click()
Dim wks As Worksheet
Dim OLEObj As OLEObject
Set wks = Worksheets("Sheet1")
For Each OLEObj In wks.OLEObjects
If TypeOf OLEObj.Object Is MSForms.OptionButton Then
MsgBox OLEObj.Name
End If
Next
End Sub
-
Feb 13th, 2009, 02:10 PM
#3
Re: Looping through controls
I'm still failing at simply looping through all the controls on my form
When you are using controls in a Form then you need to try this...
vb Code:
Private Sub CommandButton1_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "OptionButton" Then
MsgBox ctl.Name
ElseIf TypeName(ctl) = "CommandButton" Then
MsgBox ctl.Name
ElseIf TypeName(ctl) = "Frame" Then
MsgBox ctl.Name
End If
Next
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 13th, 2009, 02:45 PM
#4
Thread Starter
Hyperactive Member
Re: Looping through controls
Great Thanks! Used the latter, works perfectly... Thanks to both of you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|