Problem: Excel 2003, identify the control type..

Richard U

Active Member
Joined
Feb 14, 2006
Messages
406
Office Version
  1. 365
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
..of an OLEobject.

I've got several dozen controls that I need to reset upon opening a worksheet.

Some need to be set to false, other blank, et cetera.

Is there a way to identify their type so that I can do something like...

For each thing in sheets(1).oleobjet

'if the thing is a listbox, do "a"'
'if the thing is a checkbox, do "b

Next thing




thanks folks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi, :)

the first code "Sub Main()" You can see which types of controls you have in the active worksheet. With the second code "Sub Main_1()" you can do something else, depending on the type. Instead of "ActiveSheet" you can also specify a spreadsheet:

Code:
Option Explicit
Sub Main()
    Dim objCtrl As Object
    For Each objCtrl In ActiveSheet.OLEObjects
        Debug.Print "Name: " & objCtrl.Name
        Debug.Print "Type: " & objCtrl.progID
    Next objCtrl
End Sub
Sub Main_1()
    Dim objCtrl As Object
    For Each objCtrl In ActiveSheet.OLEObjects
        Select Case objCtrl.progID
            Case "Forms.CommandButton.1"
                ' do...
            Case "Forms.ComboBox.1"
                ' do...
            Case "Forms.CheckBox.1"
                ' do...
            Case "Forms.ListBox.1"
                ' do...
            Case "Forms.TextBox.1"
                ' do...
            Case "Forms.ScrollBar.1"
                ' do...
            Case "Forms.SpinButton.1"
                ' do...
            Case "Forms.OptionButton.1"
                ' do...
            Case "Forms.Label.1"
                ' do...
            Case "Forms.Image.1"
                ' do...
            Case "Forms.ToggleButton.1"
                ' do...
        End Select
    Next objCtrl
End Sub
The issue of "Debug.Print" is in "Immediate Window" (CTRL+G VBA-Editor).
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top