이 기사에서는 vba의 메시지 상자에 대해 알아 봅니다.

다음은 Excel에서 msgbox를 사용하는 방법에 대한 Excel vba msgbox 예제입니다.

MsgBox "The job is done !"

' messagebox with text and OK-button

MsgBox "The job is done !", vbInformation

' messagebox with text, OK-button and an information-icon

MsgBox "The job is done !", vbCritical

' messagebox with text, OK-button and a warning-icon

MsgBox "The job is done !", vbInformation, "My Title"

' messagebox with text, OK-button, information-icon and a custom title text

Answer = MsgBox("Do you want to continue ?", vbYesNo)

' messagebox with YES- and NO-buttons,

' the result is an integer, the constants are named vbYes and vbNo.

Answer = MsgBox("Do you want to continue ?", vbYesNo + vbQuestion)

' messagebox with YES- and NO-buttons and a question-icon

Answer = MsgBox("Do you want to continue ?", vbYesNo + vbQuestion, "My Title")

' messagebox with YES- and NO-buttons,

' question-icon and a custom title text

Answer = MsgBox("Do you want to continue ?", vbYesNo + 256 + vbQuestion, "My Title")

' messagebox with YES- and NO-buttons, question-icon and a custom title text,

' the NO-button is default

Answer = MsgBox("Do you want to continue ?", vbOKCancel, "My Title")

' messagebox with OK- and CANCEL-buttons, the result is an integer,

' the constants are named vbOK og vbCancel.

MsgBox-VBA 함수의 결과는 변수에 저장할 수 있습니다.

변수는 정수 유형일 수 있습니다.

이 변수는 나중에 다음과 같은 매크로 코드에서 사용할 수 있습니다.

Answer = MsgBox("Do you want to continue ?", _

vbOKCancel, "My Title")

If Answer = vbCancel Then Exit Sub ' the macro ends if the user selects the CANCEL-button

또는 다음과 같이 :

If MsgBox("Do you want to continue ?", vbOKCancel, _

"My Title") = vbCancel then Exit Sub