Public variable

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
this is not clear. for variables to work between modules, declare them as public at the top of a module outside any 'sub' statement. not certain, but i would declare the class as public if you want to initiate it in other modules.
 
Upvote 0
That article discusses two ways to write a "property" in a class module.

When I write a custom class, if there is a simple property that's just a container for a value, it can be done one of two ways.

one way declares the "property" as a public variable
Code:
' in class module

Public Tag as String

one way declares it as a Property

Code:
'in a class module

Dim pTag as String

Property Get Tag() As String
    Tag = pTag
End Property

Property Let Tag(inVal as String)
    pTag = inVal
End Property

There really isn't any difference in how the class is used. The syntax for other using that custom class wouldn't change one bit.

Code:
' in a normal module

Sub Test()
    Dim myObj as Class1

    Set myObj = New Class1
    myObj.Tag = "hello"

    MsgBox myObj.Tag
End Sub

That article is not talking about what is usually referred to as a Public variable, i.e. a variable that is available to all routines in all modules.
That article is talking about how to declare a property of a custom class.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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