ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Classes and Userform: Passing it around (https://www.excelbanter.com/excel-programming/396861-classes-userform-passing-around.html)

axwack

Classes and Userform: Passing it around
 
I created a class and a userform. The userform has certain fields of
type dates, strings, etc. all of which I set a CLASS with propertieis.
The class is created by the userform. After the user fills out the
userform, I want the class so that I can use it within my worksheet
workflow to calculate values for the worksheet.

How do I get the class after the userform is closed? Does it exist in
memory and how do I access it?


Vergel Adriano

Classes and Userform: Passing it around
 
You could expose a public property in the user form that you can use to point
to an object variable that is defined in the worksheet. In this way, the
userform would be manipulating an object that actually exists in the
worksheet. When the userform is unloaded, the object would still be
available in the worksheet.

Or, you can also declare the object variable with a global scope. For
example, in a module, declare it like this

Global obj as New YourClass

You can then access that variable anywhere in your VBA code.



--
Hope that helps.

Vergel Adriano


"axwack" wrote:

I created a class and a userform. The userform has certain fields of
type dates, strings, etc. all of which I set a CLASS with propertieis.
The class is created by the userform. After the user fills out the
userform, I want the class so that I can use it within my worksheet
workflow to calculate values for the worksheet.

How do I get the class after the userform is closed? Does it exist in
memory and how do I access it?



Jon Peltier

Classes and Userform: Passing it around
 
Declare the class in the code that launches the userform, then pass the
class to the userform as a property. Here's a simple example of userform
properties:

http://peltiertech.com/Excel/PropertyProcedures.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"axwack" wrote in message
ps.com...
I created a class and a userform. The userform has certain fields of
type dates, strings, etc. all of which I set a CLASS with propertieis.
The class is created by the userform. After the user fills out the
userform, I want the class so that I can use it within my worksheet
workflow to calculate values for the worksheet.

How do I get the class after the userform is closed? Does it exist in
memory and how do I access it?





All times are GMT +1. The time now is 08:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com