+ Reply to Thread
Results 1 to 7 of 7

Call a class sub from userform

  1. #1
    Registered User
    Join Date
    05-10-2011
    Location
    Colorado, US
    MS-Off Ver
    Excel 2010
    Posts
    4

    Call a class sub from userform

    How do I call a class sub from a userform? Is there a standard way? I have tried calling it like a regular non-class module. Then I get sub not defined and object required error messages.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Call a class sub from userform

    Unless my brain is getting jumbled between programming languages, you have to create a new instance of the class. So let's say you have a user made class called MyClass. The code would be:

    Please Login or Register  to view this content.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Call a class sub from userform

    Please be more specific. What do you want to achieve and what should tbe the result ?

    if the classname is 'Example'
    if the class contains a property 'nice'

    Please Login or Register  to view this content.



  4. #4
    Registered User
    Join Date
    05-10-2011
    Location
    Colorado, US
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Call a class sub from userform

    I want something to be added to a collection if a button is clicked. I also want something to be gotten from the collection, and put on the spreadsheet, if a button is clicked. I tried this in a public class module:
    Please Login or Register  to view this content.
    And this in a userform module:
    Please Login or Register  to view this content.
    I get object required error msg. for the line Class1.whatever. If I delete that line I get sub not defined error for the following line.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Call a class sub from userform

    the classname: 'Eventhandler'

    In the Class

    Please Login or Register  to view this content.
    In the Userform
    a commandbutton 'knop_vervolg'

    Please Login or Register  to view this content.
    Last edited by snb; 05-10-2011 at 03:23 PM.

  6. #6
    Registered User
    Join Date
    05-10-2011
    Location
    Colorado, US
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Call a class sub from userform

    I think that puts the info into a collection. How do I access an item from the collection by index #, and put it on the spreadsheet? I think the line below should go somewhere but I'm not sure where.
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    I changed the code to this:
    Please Login or Register  to view this content.

    and
    Please Login or Register  to view this content.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Call a class sub from userform

    In your first question you were talking about a userform.
    Now you introduce controls in a sheet: quite another piece of cake.
    My suggestion: implement my suggestion first, secondly try to understand it.
    Otherwise adapting is a wild (unsuccessful) gamble.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1