+ Reply to Thread
Results 1 to 5 of 5

Advice on passing userform parameters to a vba class module

  1. #1
    Registered User
    Join Date
    02-18-2011
    Location
    melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Advice on passing userform parameters to a vba class module

    Hi folks

    Is anyone able to advise me or point me in the right direction on "the correct" way to pass parameters from user-form selections into a vba class module.

    My intention is to perform calculations based on the userform parameters selected.

    I am using using a class module in order to utilize the code using similar inputs for;
    1. an interactive single calculation on a user-form
    2. and batch calculations on another user-form.

    Hope this makes sense. Thanks in advance.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Advice on passing userform parameters to a vba class module

    Hi there,

    If you want to maximise the encapsulation of your UserForm and Class modules, I suggest the following approach:

    Within an "overall" module/routine:

    Create an instance of your UserForm and display (.Show) it,

    Allow the User to enter data in the UserForm and then hide (.Hide) the UserForm,

    Retrieve the User data into the "overall" routine via appropriately-defined Properties of the UserForm,

    Create an instance of your Class,

    Pass the User data from the "overall" routine to the Class via appropriately-defined Properties of the Class.



    Taking the above approach allows the UserForm and the Class modules to remain completely "ignorant" of each other - all communication between the two modules is handled by the "overall" routine. This approach allows you to make internal modifications to either of the modules without affecting the other one.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    02-18-2011
    Location
    melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Advice on passing userform parameters to a vba class module

    Thanks for the reply Greg. That is precisely the way I have approached the issue at present and may continue on that line.

    I didn't want to reveal my method initially for fear of being growled at .

    Tyrone P.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Advice on passing userform parameters to a vba class module

    Hi again,

    You're welcome - many thanks for the feedback.

    Regards,

    Greg M

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Advice on passing userform parameters to a vba class module

    If you wanted to be really fancy and make the overall routine ignorant of the actual implementations of the userform and class, you could create interfaces for both and pass the instantiated objects into the routine. Sort of like manual dependency injection.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Add Property to UserForm via class module - please help
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-07-2016, 09:35 AM
  2. [SOLVED] Userform ComboBox Class Module not working
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2016, 03:23 AM
  3. [SOLVED] Userform & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  4. Replies: 0
    Last Post: 03-08-2014, 08:02 AM
  5. Replies: 1
    Last Post: 10-12-2012, 04:36 AM
  6. Passing parameters to class modules
    By Mats Samson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2011, 03:44 AM
  7. Passing variable from userform to module error
    By mworth01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2005, 12:47 PM

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