ExoticBirdsMerchant
ExoticBirdsMerchant

Reputation: 1496

VBA properties type

I know this is ultra basic in VBA but i have searched on 6 books (VBA for dummies 2010, Excel Bible, Proffesional Excel Development: The deffinitive guide, VBA and Macros Excel Microsoft 2010, Excel programming with VBA, Microsoft Excel VBA Proffesional Projects) and noone gives a deffinition about the 3 types of properties read-only, write-only and read/write.


They probably think is way to basic to even mention in their books but hey if you believed as i that computers were electricity purification filters 11 months ago and know you wanna code now someone has to tell ya a clean cut explanation

thanks for watching my question

Upvotes: 3

Views: 1391

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149277

As the names suggest


Read Only Property is a property from which you can read but not write to it. For example, For a range .Text is a Read Only Property

Msgbox Range("A1").Text

If you try to write to it, for example

ActiveSheet.Range("A1").Text = "Blah Blah"

then you will get the message showing an error Runtime Error 1004 - Unable to set the Text property of the Range Class


Write-only Property are moderately rare. Write Properties are simply properties that have Property Let or Set method but no Get Method.

Private MyName As String

Property Let sName(Value As String)
    MyName = Value
End Property

Read/Write Property is pretty self explanatory. You can read and write to it. For example, for a Range .Value is a Read/Write Property

Range("A1").Value = "Blah Blah"

Extra Note: Courtesy @Mehow

When you press F2 in the Visual Basic Editor, the Object Browser pops up. If you click on any of the classes and then members of that class you can see in the left bottom corner which properties are read/write.

Upvotes: 9

Related Questions