Class Modules in VBA: Made Super Simple

preview_player
Показать описание
👉 Ready to master VBA?
(Note: If the download page doesn't work then make sure to turn off any popup blockers)

Class Modules in VBA: Made Super Simple

Class Modules are the biggest stumbling block for users trying to move to the next level in VBA. Many people struggle to grasp what they are for, when to use them and how to use them in their own code. In this video I am going to show you with real-world examples, How any one can use Class Modules in their code.

#ExcelVBA #VBAClassModules #ClassModules

Useful VBA Shortcut Keys
========================

Debugging:
Compile the code: Alt + D + L OR Alt + D + Enter
Run the code from the current sub: F5
Step into the code line by line: F8
Add a breakpoint to pause the code: F9(or click left margin)

Windows:
View the Immediate Window: Ctrl + G
View the Watch Window: Alt + V + H
View the Properties Window: F4
Switch between Excel and the VBA Editor: Alt + F11
View the Project Explorer Window: Ctrl + R

Writing Code:
Search keyword under cursor: Ctrl + F3
Search the word last searched for: F3
Auto complete word: Ctrl + Space
Get the definition of the item under the cursor: Shift + F2
Go to the last cursor position: Ctrl + Shift + F2
Get the current region on a worksheet: Ctrl + Shift + 8(or Ctrl + *)
To move lines of code to the right(Indent): Tab
To move lines of code to the left(Outdent): Shift + Tab
Delete a Line: Ctrl + Y(note: this clears the clipboard)

Table of Contents:

00:00 - Introduction
01:00 - Bank Account example
02:58 - Issues with Standard VBA code
03:05 - Using a Class Module for Account
10:49 - The Elements of a Class Module
13:37 - How to use Set and New
14:45 - Guidlines for creating Class Modules
15:43 - Collection Example
Рекомендации по теме
Комментарии
Автор

Let me know of your struggles(or successes) with Class Modules in the comments below

Excelmacromastery
Автор

Words fail to adequately describe Mr. Kelly's mastery. Simply unique.

faanmuller
Автор

Inspiring as always. You really cleared the sky with this tutotrial, after 30+ years of VBA programming Classes still hold (now held) a secret for me and I just counldn't grasp the essentials.
Thanks Paul
"IT" Always crosses your path ...

hanshallebeek
Автор

El mejor video sobre módulos de clase. Gracias

pedrogutierrez
Автор

You have made this subject... So easy to follow. Absolutely FANTASTIC. THANK YOU SO MUCH!!!!

karibeauchamp
Автор

Super-clear, thanks. I wish all internet tutorials were this well-organized!

crawdad
Автор

Another excellent lecture! This video came along just at the time when I wanted to review the fundamentals of class modules in VBA. Thank you!

serdip
Автор

This video definitely is on a higher level. I'll have to view it several times. 🤔 But I will get there.☑

houstonvanhoy
Автор

Still struggling to fully “get” class’s but wrote one to help me manipulate txt files and it was very useful. Hoping I find another use.

johnbutler
Автор

thank you, i found this video very useful, now i feel the urge to learn how to write elegant code

ElectromecanicaIndustrial
Автор

Tanks Paul.

My first class module will have the method:
.SendThanksToPaul
(and I will call it inside a loop 😄)

m_marcamo
Автор

Another advantage of using Property procedures is that we can include validation code. I think that in its current state, the clsAccount class accepts negative values in the Credit() and Debit() methods, which should not be acceptable, I believe. Additionally, it seems that the Property Let Debit() procedure should not complete the transaction if the specified amount exceeds m_Balance.

Next level design would be, in my opinion, to create an interface IAccount for example, that has the properties and methods common to all kinds of accounts. Then separate classes for checking, savings, personal, commercial account types could be created, each one implementing IAccount, whose methods are exposed to the calling code but the internal implementation details, of which such as interest calculations, overdraft fees etc. would be specific to each class.

Next next level (is that a thing? LOL) would be to include RaiseEvent WarnCustomer() in the class modules that could be invoked by, say Credit() when m_Balance exceeds $250, 000 (the FDIC insurance limit, I think), or by Debit() when the remaining m_Balance falls below a threshold, which could be different depending on the type of account.


Thanks again for another very clear, concise, and eminently practical lecture on VBA development techniques.

serdip
Автор

You have given a good explanation of class in vba through this example. Thank you sir.

I need vba codes to replace an excel file stored in google drive with new version of the same file from my PC. Please guide me.

LilaBdrKarki-kbmn
Автор

Thanks Mr. Paul, Please, we want to apply it through more professional applications, so that the understanding is better.

hammeedabdo.
Автор

Very good presentation of class module

BenjaminHouot
Автор

Great introduction, love to see new videos from you.

kmslogic
Автор

Hello. You said that by writing 'Set p = New clsPoint' it is possible to define in runtime how many objects are to be created in a for loop. What that loop would look like? Would an array of type clsPoint be needed? Your content is great, thanks.

rmdfra
Автор

Fantastic information. Thank you. I have a question: how did you make the edges of your msgboxes rounded??? VBA gives me only sharp old style edges????

alterchannel
Автор

In several places you say 'copy the code' when it should be 'move' or 'cut and paste', it confused me for a moment.

derekpowles
Автор

6:55 I believe you said "methods"? I didn't know Scottish people would pronouce it that way 🤔 Had to put on subtitles to figure this one out 😁

rogerh