Public Function UniMsgbox(Optional NoiDung As String = "", _
Optional TieuDe As String = "Thông Báo", _
Optional ThoiGianDong As Byte = 1, _
Optional KieuNutLenh As Byte = 0, _
Optional KieuIcon As Byte = 0, _
Optional LenhMacDinh As Byte = 1)
Rem 'KieuNutLenh: 0 -OK | 1 -OK Cancel | 2 - Abort Retry Ignore | 3 - Yes No CanCel | 4- Yes No | 5- Retry Cancel
Rem 'KieuIcon: 16 -(X) | 32-(?) | 48-/!\ | 64-(!) | 0-....
Rem 'UniMsgbox: 1 -OK | 2 - Cancel | 3 - Abort | 4 - Retry | 5- Ignore | 6- Yes | 7- No
LenhMacDinh = WorksheetFunction.Min(WorksheetFunction.Max(LenhMacDinh, 1), 3)
UniMsgbox = CreateObject("Wscript.shell").PopUp(NoiDung, ThoiGianDong, TieuDe, KieuNutLenh + KieuIcon + (LenhMacDinh - 1) * 256)
If UniMsgbox = -1 And KieuNutLenh > 0 Then
Dim Arr As Variant
Arr = Switch(LenhMacDinh = 1, Array(1, 3, 6, 6, 4), LenhMacDinh = 2, Array(2, 4, 7, 7, 2), LenhMacDinh = 3, Array(2, 5, 2, 7, 2))
UniMsgbox = Arr(KieuNutLenh - 1)
End If
End Function
Sub TEST1()
Dim Arr As Variant
Arr = Array("", "OK", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No")
UniMsgbox "Gia tri Msgbox tra ve : " & Arr(UniMsgbox("Dung Co Chon Gi Het Nha", "Test", 1, 3, 0, 1))
UniMsgbox "Gia tri Msgbox tra ve : " & Arr(UniMsgbox("Dung Co Chon Gi Het Nha", "Test", 1, 3, 0, 2))
UniMsgbox "Gia tri Msgbox tra ve : " & Arr(UniMsgbox("Dung Co Chon Gi Het Nha", "Test", 1, 3, 0, 3))
End Sub