VBA and Class Problem

AlmostVinDiesel

New Member
Joined
Oct 26, 2005
Messages
18
I'm having a problem with Excel VBA and Classes. I can't get the member variables to store any information. Can anyone help please? Code is below:



'Class Module: Campaign
'-------------------------------------------------------------------------------------
Private pCampaign As String

Public Property Get Campaign() As String
Campaign = pCampaign
End Property

Public Property Let Campaign(s As String)
pCampaign = s
End Property

'-------------------------------------------------------------------------------------
'Regular Module
Sub Test()
Dim record As Campaign
Set record = New Campaign
record.Campaign = "test"
Range(Cells(1, 1), Cells(1, 1)) = record.Campaign 'But nothing is stored!
End Sub

'Nothing is stored in the Cell A1. Can anyone help?

Thanks!

~John
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
John

Why are you using a class module in the first place?:)
 
Upvote 0
John

It really depends what you are trying to do.

Class modules are used for/exist for various reasons.

What are you actually trying to do?
 
Upvote 0
I would like to use classes. There are about 15 member vars to this class, and I have about 5 other classes I want.. I'v ejust shown a snippet (I'm developing an application to monitor campaigns, and I'd prefer to go the oop route).

Any idea why what I've written isn't working?
 
Upvote 0
Well if you want to go the 'OOP' route I think you might have taken a wrong turn.:)

VBA is not an OOP language.:)
 
Last edited:
Upvote 0
John,

It worked fine for me.

I created a class module, called it ampaign then ran the test code. Test was stored in A1 as expected.
 
Upvote 0

Forum statistics

Threads
1,216,022
Messages
6,128,325
Members
449,440
Latest member
Gillian McGovern

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top