Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:54:48+00:00 2026-06-09T07:54:48+00:00

I am trying to implement Inheritance in VBA in the following way – I

  • 0

I am trying to implement Inheritance in VBA in the following way –

I have one class module clsRange as shown below

Private strRngName as String

Public Property Let RangeName(ByVal thisRangeName As String)
    strRngName = thisRangeName
End Property

Public Property Get RangeName() As String
    RangeName= strRngName
End Property

Another class module clsChildRange

private rngHolder as New clsRange

Public Property Get RangeName() As String
   Set RangeName = rngHolder.RangeName
End Property

Public Property Let RangeName(ByVal thisRangeName As String)
    rngHolder.RangeName = thisRangeName
End Property

I have a module, In that I am trying to create an object for clsChildRange and try to set the properties of clsRange in the following way

Dim objCRng  as New clsChildRange

objCRng.RangeName= "Range1"

But I get an error – object variable or with block variable not set.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:54:49+00:00Added an answer on June 9, 2026 at 7:54 am

    As Uri said, rngHolder is not instantiated which is causing the problem. Don’t test for Null, but test of Is Nothing. Here are two ways to do this, depending on what you’re trying to accomplish.

    Explicitly Set the Range

    In CRange

    Private msRngName As String
    
    Public Property Let RngName(ByVal sRngName As String): msRngName = sRngName: End Property
    Public Property Get RngName() As String: RngName = msRngName: End Property
    

    In CChildRange

    Private mclsRange As CRange
    
    Public Property Set Range(ByVal clsRange As CRange): Set mclsRange = clsRange: End Property
    Public Property Get Range() As CRange: Set Range = mclsRange: End Property
    
    Public Property Get RngName() As String
    
        If Not Me.Range Is Nothing Then
            RngName = Me.Range.RngName
        End If
    
    End Property
    
    Public Property Let RngName(sName As String)
    
        If Not Me.Range Is Nothing Then
            Me.Range.RngName = sName
        End If
    
    End Property
    

    Then in a standard module

    Sub test()
    
        Dim clsRange As CRange
        Dim clsChildRange As CChildRange
    
        'Create a new CRange instance
        Set clsRange = New CRange
    
        'Create a new CChildRange instance
        Set clsChildRange = New CChildRange
    
        'Set the Range property to the CRange instance
        Set clsChildRange.Range = clsRange
    
        'Set the RngName property of the chile
        clsChildRange.RngName = "Range1"
    
        'Test that the parent has the property set
        Debug.Assert clsRange.RngName = "Range1"
    
    End Sub
    

    Implicitly set the Range

    CRange is the same.

    In CChildRange

    Private mclsRange As CRange
    
    Public Property Set Range(ByVal clsRange As CRange): Set mclsRange = clsRange: End Property
    Public Property Get Range() As CRange: Set Range = mclsRange: End Property
    
    Public Property Get RngName() As String
    
        RngName = Me.Range.RngName
    
    End Property
    
    Public Property Let RngName(sName As String)
    
        Me.Range.RngName = sName
    
    End Property
    
    Private Sub Class_Initialize()
    
        Set mclsRange = New CRange
    
    End Sub
    
    Private Sub Class_Terminate()
    
        Set mclsRange = Nothing
    
    End Sub
    

    Then in a standard module

    Sub test()
    
        Dim clsChildRange As CChildRange
    
        'Create a new CChildRange instance
        'Range object created when class is created
        Set clsChildRange = New CChildRange
    
        'Set the RngName property of the chile
        clsChildRange.RngName = "Range1"
    
        'Test that the parent has the property set
        Debug.Assert clsChildRange.Range.RngName = "Range1"
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement class inheritance hieararchy with NHibernate and SQL server. I made
In the following code i am trying to implement inheritance and polymorphism properties,My question
I am trying to implement a way to achieve inheritance in JavaScript. First I
I'm trying to implement abstract inheritance in Django with the following code, but it
I'm trying to implement a TPC inheritance model in EF 4.3 CodeFirst for an
I'm trying to implement a facebook like like relationship. I wanted to use inheritance
I am trying to come up with the best way to implement SQL Data
I have the following class and extension class (for this example): public class Person<T>
I'm trying to extend functionality of the VBA Collection object in a new class
I've been trying to learn more about private inheritance and decided to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.