From the course: Excel VBA: Process Modeling

Create a class module

From the course: Excel VBA: Process Modeling

Start my 1-month free trial

Create a class module

- When you create a simulation, you model the behavior of business objects, such as customers, as they move through an environment. That environment is made up of other business objects, such as customer service stations within a store or some other location. In this movie, I will show you how to create a class module. A class module is a structure within Excel VBA that you can use to hold class definitions. Those definitions could represent customers or service stations within your store. The sample file I'm using is chapter oh-one oh-one, and that's an Excel workbook you can find in the chapter one folder of the exercise files collection. We're not going to work with anything in a worksheet so I'll switch to the visual basic editor by pressing alt F11. Now that I'm here in the visual basic editor, I can create a class module. To do that, I will go to the insert menu and then the last item that's available for me to click is class module, so I'll go ahead and click it. When I do, a class module appears. You can also see it over in the VBA project explorer. If you don't see the VBA project explorer, you can go to the View menu and click project explorer. We will also work with the properties window below. If you don't see that, press F4 or come to the same menu and click properties window. But in this case everything is visible, so I'll just click away. The last thing I want to do in this movie is to change the name of this class module. I'll make sure the class module is selected and then it appears in the properties window below. Then I'll go down to the name category and in the text box to the right, it says class one, I will backspace over the existing name and I will call this class CCustomer. So C-C-u-s-t-o-m-e-r, and enter. The reason that you use a capital C in front of this object's name is to indicate that it is a class. It's not strictly necessary. Nothing bad will happen if you don't do it, but it's a great way to remind yourself that when you see CCustomer you're looking at a class that defines a customer.

Contents