Excel VBA AI Assistant LogoExcel VBA AI Assistant
    Expert
    VBA
    OOP
    Class Modules
    Architecture
    Featured

    Class Modules in VBA: Object-Oriented Programming for Advanced Users

    Use class modules to structure complex VBA projects with clear domain models and reusable logic.

    VBA AI Team
    Published on August 17, 2025
    14 min read

    Class Modules in VBA: Object-Oriented Programming for Advanced Users

    Model domain concepts with properties and methods.


    Define a class

    Insert → Class Module (e.g., CInvoice)

    ' CInvoice.cls Option Explicit Private pNumber As String Private pAmount As Double Public Property Get Number() As String: Number = pNumber: End Property Public Property Let Number(ByVal v As String): pNumber = v: End Property Public Property Get Amount() As Double: Amount = pAmount: End Property Public Property Let Amount(ByVal v As Double): pAmount = v: End Property Public Function Net(ByVal vat As Double) As Double Net = Amount / (1 + vat) End Function

    Use the class

    Sub Demo() Dim inv As CInvoice: Set inv = New CInvoice inv.Number = "2025-001": inv.Amount = 119 Debug.Print inv.Net(0.19) End Sub

    Work faster with the VBA Assistant

    Create, explain, and improve your VBA code with examples, comments, and best practices—directly in your workflow.