Khi sử dụng hàm MsgBox(), có trường hợp hàm sẽ báo lỗi nếu không có cặp dấu ngoặc, trường hợp khác thì lại không báo lỗi. Ví dụ:
Sub click_to_quit_program()
Dim my_case As VbMsgBoxResult
Dim buttons As VbMsgBoxStyle
Dim title As String
Dim prompt As String
buttons = vbYesNoCancel + vbQuestion + vbDefaultButton1
title = "VBA Testing program"
prompt = "Do you wan to quit the program?"
my_case = MsgBox(prompt, buttons, title) >>>nếu bỏ dấu cặp dấu ngoặc ở đây, chương trình sẽ báo lỗi<<<
If my_case = vbYes Then
MsgBox "You choose Yes button.", vbInformation, title >>>chương trình chạy bình thường dù không có cặp dấu ngoặc<<<
ElseIf my_case = vbNo Then
MsgBox "You choose No button.", vbCritical, title
ElseIf my_case = vbCancel Then
MsgBox "You choose Cancel button.", vbExclamation, title
End If
End Sub
Mong giảng viên giải thích giúp em. Em cám ơn.