+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: Class module with ActiveX ComboBox

  1. #16
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Class module with ActiveX ComboBox

    If I load it from this forum (into the browser, or into Excel) no problem arises.
    You can save the file first on your computer/ open Excel/ open the workbook.



  2. #17
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Class module with ActiveX ComboBox

    code in the class-module

    Public WithEvents mCombo As MSForms.ComboBox
    Private Sub mCombo_Change()
     MsgBox "You changed " & mCombo.Name
    End Sub

    code in the Workbook-module
    Public col_Events As New Collection
    Sub Workbook_Open()
      For Each ctl In Sheets(1).OLEObjects
        If LCase(TypeName(ctl.Object)) = "combobox" Then
          ctl.Object.List = Array("A", "B", "C")
          col_Events.Add New clsActiveXevents
          Set col_Events(col_Events.Count).mCombo = ctl.Object
        End If
      Next
    End Sub



  3. #18
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Class module with ActiveX ComboBox

    I am still unable to open it even with Excel open first.
    Anyway thank you for posting the code. The List command is much better and usefull than the AddItem !

  4. #19
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Class module with ActiveX ComboBox

    Hi oro77

    I only included the ActiveX code so you could see how it could be done; I still recommend (as per post #2) that you to use the Forms controls because they are more reliable and (clearly) simpler to implement! Sure, they're lightweight so there are some things you can't do with them that you can do with their ActiveX equivalents but, if you need something fancier than the Forms controls can do, then you should probably be using a userform, not a worksheet.


    Btw, you'll notice that the ActiveX code I posted deliberately avoids the use of Public variables in the class modules: I declared them with Private scope and exposed them using properties ('getters', 'letters' and 'setters').



    @snb
    Quote Originally Posted by snb
    - not every event can be handled by a class module (don't ask me why)
    Are you referring to AfterUpdate, BeforeUpdate, Enter and Exit?
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  5. #20
    Registered User
    Join Date
    08-31-2011
    Location
    Tokyo
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Class module with ActiveX ComboBox

    Hello Colin Legg

    Thanks for your comments.
    I also thought about using a userform but I don't know how many combo box will be needed, it is kind of dynamic and I am afraid that by using userform, I may not need have enough space to place them all.
    I guess the useform size could be dynamic too but if it becomes too large, it would be bad :P

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0