VBA Property(属性) 笔记
Property Let Statement
Property Get Statement
Property Set Statement
From: http://msdn.microsoft.com/en-us/library/aa266200(v=vs.60).aspx
Property Let Statement Example
This example uses the Property Let statement to define a procedure that assigns a value to a property. The property identifies the pen color for a drawing package.
Dim CurrentColor As Integer
Const BLACK = 0, RED = 1, GREEN = 2, BLUE = 3
' Set the pen color property for a Drawing package.
' The module-level variable CurrentColor is set to
' a numeric value that identifies the color used for drawing.
Property Let PenColor(ColorName As String)
Select Case ColorName ' Check color name string.
Case "Red"
CurrentColor = RED ' Assign value for Red.
Case "Green"
CurrentColor = GREEN ' Assign value for Green.
Case "Blue"
CurrentColor = BLUE ' Assign value for Blue.
Case Else
CurrentColor = BLACK ' Assign default value.
End Select
End Property
' The following code sets the PenColor property for a drawing package
' by calling the Property let procedure.
PenColor = "Red"
From:http://msdn.microsoft.com/en-us/library/aa266194(v=vs.60).aspx
Property Get Statement Example
This example uses the Property Get statement to define a property procedure that gets the value of a property. The property identifies the current color of a pen as a string.
Dim CurrentColor As Integer
Const BLACK = 0, RED = 1, GREEN = 2, BLUE = 3
' Returns the current color of the pen as a string.
Property Get PenColor() As String
Select Case CurrentColor
Case RED
PenColor = "Red"
Case GREEN
PenColor = "Green"
Case BLUE
PenColor = "Blue"
End Select
End Property
' The following code gets the color of the pen
' calling the Property Get procedure.
ColorName = PenColor
From:http://msdn.microsoft.com/en-us/library/aa266205(v=vs.60).aspx
Property Set Statement Example
This example uses the Property Set statement to define a property procedure that sets a reference to an object.
' The Pen property may be set to different Pen implementations.
Property Set Pen(P As Object)
Set CurrentPen = P ' Assign Pen to object.
End Property

浙公网安备 33010602011771号