Results 1 to 10 of 10

Thread: Excel: Checkbox - Application-defined or obkect-defined error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Exclamation Excel: Checkbox - Application-defined or obkect-defined error

    Hi,

    I have the created the following procedure in Excel 2010, which should loop through each of the checkboxes on a given sheet and will expand of collapse depending on each checkbox's value

    I am attempting to run the same procedure in Excel 2007, but I am receiving the above error.
    I have checked that I have the same references added to the workbook and all appears to be ok.

    Has anyone come across this issue before, or can you advise where I may be going wrong?

    Thanks
    Mitch

    Code:
    Sub expand_collapse_treatments()
    Dim cell As Range
    Dim shp As CheckBox
    Application.ScreenUpdating = False
    
    
    
    
    For Each shp In front.CheckBoxes
            If shp.Value = 1 Then
                Call show_hide_rows(shp.Caption, 1)
            Else
                Call show_hide_rows(shp.Caption, 0)
            End If
    Next shp
    
    Application.ScreenUpdating = True
    
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    what is front?
    if it is a worksheet, you need to loop through the shapes collection, then determine if each shape is a checkbox, then use the value accordingly
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    Thanks for your reply westconn1

    This works on my personal PC with Office 2010, but not my work PC with Office 2010 and 2007.

    I am looping through the checkbox collection, so I shouldn’t have to determine whether the shape is a checkbox should I?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    Also,

    front is a worksheet within the workbook

    I have tried looping through the shapes too, but it does not appear to acknowledge the existence of the checkboxes...

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    try like this
    vb Code:
    1. Dim s As Worksheet, c As Shape
    2. Set s = Sheets("sheet2")
    3. For Each c In s.Shapes
    4.     If c.OLEFormat.Object.ProgId = "Forms.CheckBox.1" Then
    5.         ' do stuff
    6.         chked = c.OLEFormat.Object.Object.Value
    7.         MsgBox c.OLEFormat.Object.Object.Caption & vbNewLine & chked
    8.     End If
    9. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    Thanks for your reply, I've used your code to loop through the objects on my front sheet

    When it gets to a drop down or checkbox it fails saying

    Object does not support this property or method

    I'm stumped!

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    what type of checkboxes are they?
    are controls or forms checkboxes?
    the default name for an added control would be like CheckBox1, where as a froms checkbox would be like Check Box 1
    they are different of different type
    c.type = 12 for a control or 8 for a forms checkbox
    the code i posted is to work with controls

    try inserting the extra line
    vb Code:
    1. For Each c In s.Shapes
    2.       If c.Type = 8 Then MsgBox c.OLEFormat.Object.Value = 1: Exit Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    Same message when I try that code

    I can't remember whether I chose activeX or Form controls, but I am prompted to load ActiveX controls when I load the message...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    Just checked, one of them is called Check Box 9

    so it must be a forms control...?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Checkbox - Application-defined or obkect-defined error

    so it must be a forms control...?
    looks like,
    i tested the code i posted above in excel 2000, afaik there should be no problem with it running in excel 2007, but i believe controls have some other name in the later version
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width