본문 바로가기

공부/VBA

VBA - Me keyword

Private Sub OKButton_Click()
    'Routines...
    Unload Me
End Sub


 

Me <keyword>

The Me keyword behaves like an implicitly declared variable. It is automatically available to every procedure in a class module. When a class can have more than one instance, Me provides a way to refer to the specific instance of the class where the code is executing. Using Me is particularly useful for passing information about the currently executing instance of a class to a procedure in another module. For example, suppose you have the following procedure in a module:

Sub ChangeFormColor(FormName As Form)
    FormName.BackColor = RGB(Rnd * 256, Rnd * 256, Rnd * 256)
End Sub

You can call this procedure and pass the current instance of the Form class as an argument using the following statement:

ChangeFormColor Me

'공부 > VBA' 카테고리의 다른 글

VBA - format 함수 사용법  (0) 2011.04.19
VBA - Type Conversion Functions  (0) 2011.04.18
VBA - The On Error Statement  (0) 2011.04.18