Public Function MessageBox(Optional ByVal strPrompt As String, _
Optional ByVal vbButtons As VbMsgBoxStyle = vbMsgBoxHelpButton, _
Optional ByVal strTitle As String, _
Optional ByVal strHelpFile As String, _
Optional ByVal varContext, _
Optional ByVal lngKey As Long, _
Optional ByVal blnMessageBox As Boolean = True, _
Optional ByVal varReturnValue As Variant)
If blnMessageBox = False Then Exit Function
lngKey = Err.Number
If lngKey = 0 Then lngKey = CLng(vbButtons)
If strHelpFile = "" Then strHelpFile = ThisWorkbook.Path & "\Help.chm"
If IsMissing(varContext) Then varContext = 0
If Err.Number <> 0 Then
If strTitle = "" Then strTitle = "Loi he thong: " & Err.Number
strPrompt = "Khong thuc hien duoc vi:" & vbNewLine & _
"Lçi " & Err.Number & " - " & Err.Description
If vbButtons = vbMsgBoxHelpButton Then
vbButtons = vbCritical + vbMsgBoxHelpButton
Else
vbButtons = vbButtons + vbMsgBoxHelpButton
End If
Else
If strTitle = "" Then strTitle = "Thong bao!"
End If
Select Case vbButtons
Case vbMsgBoxHelpButton
vbButtons = vbInformation
Case vbYesNo, vbYesNoCancel, vbRetryCancel, vbAbortRetryIgnore
vbButtons = vbButtons + vbQuestion
Case vbOK
vbButtons = vbButtons + vbInformation
End Select
vbButtons = vbButtons + vbMsgBoxHelpButton
If IsMissing(varReturnValue) Then
MessageBox = MsgBox(strPrompt, vbButtons, strTitle, strHelpFile, varContext)
Else
MsgBox strPrompt, vbButtons, strTitle, strHelpFile, varContext
MessageBox = varReturnValue
End If
End Function