Hỏi thêm về MsgBox ? (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Hoàng Nhật Phương

Thành viên gắn bó
Tham gia
5/11/15
Bài viết
1,895
Được thích
1,219
Xin chào các bạn,
Tôi đang có đoạn code sau:

Mã:
Sub TestMsgBox_()
    Application.Assistant.DoAlert "MsgBox", _
        "Do you want to continue ?", _
        msoAlertButtonYesNoCancel, msoAlertIconCritical, msoAlertDefaultFirst, msoAlertCancelDefault, False
End Sub

Untitled.jpg

Làm thế nào để khi:
chọn Yes thì xóa dữ liệu ô A1.
Chọn No thì xóa dữ liệu ô A2.
Chọn Cacel thì không làm gì cả.
 
Thử đoạn sau...
Mã:
Sub TestMsgBox()
Dim mgb As Integer
mgb = MsgBox("Do you want to continue ?", vbYesNoCancel, "MsgBox")
If mgb = vbYes Then Range("A1").ClearContents
If mgb = vbNo Then Range("A2").ClearContents
If mgb = vbCancel Then Exit Sub
End Sub
 
Upvote 0
Code trên xử lý message theo kiểu gọi sub.
Nếu muốn nó dựa vào phản ứng của người dùng thì phải gọi DoAlert theo kiểu hàm để nó trả về giá trị của nút được clicked.

Select Case Application.Assistant.DoAlert ("MsgBox", _
"Do you want to continue ?", _
msoAlertButtonYesNoCancel, msoAlertIconCritical, msoAlertDefaultFirst, msoAlertCancelDefault, False)
Case vbYes:
xóa dữ liệu ô A1
Case vbNo:
xóa dữ liệu ô A2
Case vbCancel:
không làm gì cả
End Select
 
Upvote 0
Code trên xử lý message theo kiểu gọi sub.
Nếu muốn nó dựa vào phản ứng của người dùng thì phải gọi DoAlert theo kiểu hàm để nó trả về giá trị của nút được clicked.

Select Case Application.Assistant.DoAlert ("MsgBox", _
"Do you want to continue ?", _
msoAlertButtonYesNoCancel, msoAlertIconCritical, msoAlertDefaultFirst, msoAlertCancelDefault, False)
Case vbYes:
xóa dữ liệu ô A1
Case vbNo:
xóa dữ liệu ô A2
Case vbCancel:
không làm gì cả
End Select

Chính xác cái mà tôi đang cần.
đối với tôi sử dụng msgbox dạng này thì sẽ tiện hơn khi sử dụng tiếng việt có dấu (unicode dựng sẵn).
 
Lần chỉnh sửa cuối:
Upvote 0
Các bạn cho hỏi:
Với các dùng DoAlert này ta có thể thay các tên: Yes/No/Canccel bằng các tên khác như Có/Không/Hủy được không?
Nếu có xin được được chỉ dẫn.

Cảm ơn.
 
Upvote 0
Upvote 0


Bên đó tôi thấy khó hiểu và khó ứng dụng quá.
Với cách của bài 3 bạn có thể thay các tên: Yes/No/Canccel bằng các tên khác như XóaA1/XóaA2/Hủy để khi:

chọn XóaA1 thì xóa dữ liệu ô A1.
Chọn XóaA2 thì xóa dữ liệu ô A2.
Chọn Hủy thì không làm gì cả.

được không ?

Cảm ơn
 
Upvote 0
Bên đó tôi thấy khó hiểu và khó ứng dụng quá.
Với cách của bài 3 bạn có thể thay các tên: Yes/No/Canccel bằng các tên khác như XóaA1/XóaA2/Hủy để khi:

chọn XóaA1 thì xóa dữ liệu ô A1.
Chọn XóaA2 thì xóa dữ liệu ô A2.
Chọn Hủy thì không làm gì cả.

được không ?

Cảm ơn

Code đơn giản vậy làm sao keo Tiếng Việt có dấu được ...Muốn Tiếng việt có dấu Phải viết thêm một mớ code nữa
 
Upvote 0
Bên đó tôi thấy khó hiểu và khó ứng dụng quá.
Với cách của bài 3 bạn có thể thay các tên: Yes/No/Canccel bằng các tên khác như XóaA1/XóaA2/Hủy để khi:

chọn XóaA1 thì xóa dữ liệu ô A1.
Chọn XóaA2 thì xóa dữ liệu ô A2.
Chọn Hủy thì không làm gì cả.

được không ?

Cảm ơn

Vậy bạn muốn nó xoá ô khác thì sao.
Nếu như bạn muốn theo ý bạn thì làm trên useform đi. Bạn muốn tên nó là gì cũng đc.
 
Upvote 0
Đấy chỉ là ví dụ thôi mà bạn.
Còn xóa cái gì hay làm cái gì thì người dùng có thể tự thay thế mà.
 
Upvote 0
Cố lên anh Mạnh ơi !!!!!!!! ;;;;;;;;;;;
Em cảm ơn anh.

đây muốn dễ hiểu thì Mạnh Mượn code Của Nghĩa Đẹp trai Viết Thêm một Hàm cỏn con là: UniMsgbox cho dễ hiểu và xài nha
Chép hết Mớ sau Vào một Module ...Mình làm mẫu cho 3 cái đó

Link Nghĩa Nè
http://www.giaiphapexcel.com/forum/...-font-Unicode-tuyệt-đẹp!-(Phần-2-32bit-64bit)
Mã:
'------------------------------------------------------------------------
Private hHook As Long
'******************************************************************************************************************************
#If VBA7 Then  'Office 64-bit
    Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
    Private Declare PtrSafe Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextW" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As LongPtr, ByVal lpString As LongPtr) As Long
    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As LongPtr) As Long
    Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
#Else ' Office 32-bit
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    Private Declare Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextW" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As Long) As Long
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
#End If
'******************************************************************************************************************************
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
''------------------------------------------------------------------------
Private Const IdOK = 1
Private Const IdCancel = 2
Private Const IdAbort = 3
Private Const IdRetry = 4
Private Const IdIgnore = 5
Private Const IdYes = 6
Private Const IdNo = 7
Private Const IdYesAll = 8
'------------------------------------------------------------------------
Private Const strAllButton As String = "63006800e2004103700020006e006800e20023036e00,6800e71e790020006200cf1e,6800e71e790020006e00670061006e006700,74006800ed1e20006c00a11e6900,4200cf1e2000710075006100,4300f300,6b006800f4006e006700,4300f30020007400a51e740020006300a31e"
'******************************************************************************************************************************


Private Function MsgBoxHookProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim i As Long
    Dim strButton() As String
    If lMsg = HCBT_ACTIVATE Then
        strButton = Split(strAllButton, ",")
        For i = IdOK To IdYesAll
          SetDlgItemText wParam, i, StrPtr(HexASCIIToString(strButton(i - 1)))
        Next i
        UnhookWindowsHookEx hHook
    End If
    MsgBoxHookProc = False
End Function
'******************************************************************************************************************************


Function MyUniMsgBox(ByVal msgTitle As String, _
                     Optional msgText As String, _
                     Optional msgButtonType As MsoAlertButtonType, _
                     Optional msgIconType As MsoAlertIconType, _
                     Optional msgDefaultType As MsoAlertDefaultType) As VbMsgBoxResult
    ''---------------------------------------------------------------------------------------------------
    ''Cau truc: MyUniMsgBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
    ''---------------------------------------------------------------------------------------------------
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, GetCurrentThreadId)
    On Error Resume Next
    MyUniMsgBox = Assistant.DoAlert(msgTitle, _
                                    msgText, _
                                    msgButtonType, _
                                    msgIconType, _
                                    msgDefaultType, _
                                    msoAlertCancelDefault, _
                                    False)
    If Err.Number Then
        Err.Clear
        MyUniMsgBox = Assistant.DoAlert(msgTitle, _
                                        msgText, _
                                        msgButtonType, _
                                        msgIconType, _
                                        msoAlertDefaultFirst, _
                                        msoAlertCancelDefault, _
                                        False)
    End If
End Function
'******************************************************************************************************************************
Private Function HexASCIIToString(ByVal strASCII As String) As String
  Dim i         As Long
  Dim K         As Long
  Dim bytArr()  As Byte
  i = Len(strASCII) \ 2
  If i > 0 Then
    ReDim bytArr(0 To i - 1)
    For i = 1 To Len(strASCII) - 1 Step 2
      bytArr(K) = CLng("&H" & Mid$(strASCII, i, 2))
      K = K + 1
    Next i
  End If
  HexASCIIToString = bytArr()
End Function


Sub Main_MyUniMsgBox()
    Dim Str1 As String, KM As String, KT As String
    Str1 = "Written by Hoàng Tr" & ChrW(7885) & "ng Ngh" & ChrW(297) & "a" & vbCrLf _
    & "Gi" & ChrW(7843) & "i Pháp Excel Công C" & ChrW(7909) & " Tuy" & ChrW(7879) _
    & "t V" & ChrW(7901) & "i C" & ChrW(7911) & "a B" & ChrW(7841) & "n !!!"
    KM = "Ngh" & ChrW(297) & "a " & ChrW(272) & ChrW(7865) & "p Trai"
    KT = MyUniMsgBox(KM, Str1, 3, 111) ''<- Thay doi Tham So Sau no lay ICO Sytem32 cua Win
    If KT = vbYes Then
        MsgBox "Ban Chon Co", , "Thông Báo"
    ElseIf KT = vbCancel Then
        MsgBox "Ban Chon Huy Bo", , "Thông Báo"
    Else
        MsgBox "Ban Chon Khong", , "Thông Báo"
    End If
End Sub


Sub Main2_MyUniMsgBox()
    Dim Str1 As String, KM As String, KT As String
    Str1 = "Written by Hoàng Tr" & ChrW(7885) & "ng Ngh" & ChrW(297) & "a" & vbCrLf _
    & "Gi" & ChrW(7843) & "i Pháp Excel Công C" & ChrW(7909) & " Tuy" & ChrW(7879) _
    & "t V" & ChrW(7901) & "i C" & ChrW(7911) & "a B" & ChrW(7841) & "n !!!"
    KM = "Ngh" & ChrW(297) & "a " & ChrW(272) & ChrW(7865) & "p Trai"
    KT = MyUniMsgBox(KM, Str1, msoAlertIconInfo, 14)
    If KT = vbYes Then
        MsgBox "Ban Chon Co", , "Thông Báo"
    Else
        MsgBox "Ban Chon Khong", , "Thông Báo"
    End If
End Sub

Function UniMsgbox(Optional ByVal TieuDe As String = "", Optional ByVal NoiDung As String, _
                   Optional ByVal Buuton As Long, Optional ByVal Icon As Long)
    Rem Cau truc: UniMsgBox [Tieu De], [Noi Dung], [Kieu Nut Lenh], [Kieu Icon]
    If TieuDe = "" Then TieuDe = ("Th" & ChrW(244) & "ng B" & ChrW(225) & "o") ''Thông Báo
    UniMsgbox = MyUniMsgBox(TieuDe, NoiDung, Buuton, Icon)
End Function


Sub Main_UniMsgbox()
    Dim TB As String, NoiDung As String, x
    TB = "Thông Báo"
    NoiDung = "Ki" & ChrW(7873) & "u M" & ChrW(7841) & "nh" _
                & vbLf & "Tr" & ChrW(226) & "n Tr" & ChrW(7885) & "ng Th" & ChrW(244) & "ng B" & ChrW(225) & "o"
    x = UniMsgbox(TB, NoiDung, 3, 111)
    If x = vbYes Then
        MsgBox "Yes"
    ElseIf x = vbNo Then
        MsgBox "No"
    Else
        MsgBox "Cancel"
    End If
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0
đây muốn dễ hiểu thì Mạnh Mượn code Của Nghĩa Đẹp trai Viết Thêm một Hàm cỏn con là: UniMsgbox cho dễ hiểu và xài nha
Chép hết Mớ sau Vào một Module ...Mình làm mẫu cho 3 cái đó

Link Nghĩa Nè
http://www.giaiphapexcel.com/forum/...-font-Unicode-tuyệt-đẹp!-(Phần-2-32bit-64bit)
Mã:
'------------------------------------------------------------------------
Private hHook As Long
'******************************************************************************************************************************
#If VBA7 Then  'Office 64-bit
    Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
    Private Declare PtrSafe Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextW" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As LongPtr, ByVal lpString As LongPtr) As Long
    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As LongPtr) As Long
    Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
#Else ' Office 32-bit
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    Private Declare Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextW" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As Long) As Long
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
#End If
'******************************************************************************************************************************
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
''------------------------------------------------------------------------
Private Const IdOK = 1
Private Const IdCancel = 2
Private Const IdAbort = 3
Private Const IdRetry = 4
Private Const IdIgnore = 5
Private Const IdYes = 6
Private Const IdNo = 7
Private Const IdYesAll = 8
'------------------------------------------------------------------------
Private Const strAllButton As String = "63006800e2004103700020006e006800e20023036e00,6800e71e790020006200cf1e,6800e71e790020006e00670061006e006700,74006800ed1e20006c00a11e6900,4200cf1e2000710075006100,4300f300,6b006800f4006e006700,4300f30020007400a51e740020006300a31e"
'******************************************************************************************************************************


Private Function MsgBoxHookProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim i As Long
    Dim strButton() As String
    If lMsg = HCBT_ACTIVATE Then
        strButton = Split(strAllButton, ",")
        For i = IdOK To IdYesAll
          SetDlgItemText wParam, i, StrPtr(HexASCIIToString(strButton(i - 1)))
        Next i
        UnhookWindowsHookEx hHook
    End If
    MsgBoxHookProc = False
End Function
'******************************************************************************************************************************


Function MyUniMsgBox(ByVal msgTitle As String, _
                     Optional msgText As String, _
                     Optional msgButtonType As MsoAlertButtonType, _
                     Optional msgIconType As MsoAlertIconType, _
                     Optional msgDefaultType As MsoAlertDefaultType) As VbMsgBoxResult
    ''---------------------------------------------------------------------------------------------------
    ''Cau truc: MyUniMsgBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
    ''---------------------------------------------------------------------------------------------------
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, GetCurrentThreadId)
    On Error Resume Next
    MyUniMsgBox = Assistant.DoAlert(msgTitle, _
                                    msgText, _
                                    msgButtonType, _
                                    msgIconType, _
                                    msgDefaultType, _
                                    msoAlertCancelDefault, _
                                    False)
    If Err.Number Then
        Err.Clear
        MyUniMsgBox = Assistant.DoAlert(msgTitle, _
                                        msgText, _
                                        msgButtonType, _
                                        msgIconType, _
                                        msoAlertDefaultFirst, _
                                        msoAlertCancelDefault, _
                                        False)
    End If
End Function
'******************************************************************************************************************************
Private Function HexASCIIToString(ByVal strASCII As String) As String
  Dim i         As Long
  Dim K         As Long
  Dim bytArr()  As Byte
  i = Len(strASCII) \ 2
  If i > 0 Then
    ReDim bytArr(0 To i - 1)
    For i = 1 To Len(strASCII) - 1 Step 2
      bytArr(K) = CLng("&H" & Mid$(strASCII, i, 2))
      K = K + 1
    Next i
  End If
  HexASCIIToString = bytArr()
End Function


Sub Main_MyUniMsgBox()
    Dim Str1 As String, KM As String, KT As String
    Str1 = "Written by Hoàng Tr" & ChrW(7885) & "ng Ngh" & ChrW(297) & "a" & vbCrLf _
    & "Gi" & ChrW(7843) & "i Pháp Excel Công C" & ChrW(7909) & " Tuy" & ChrW(7879) _
    & "t V" & ChrW(7901) & "i C" & ChrW(7911) & "a B" & ChrW(7841) & "n !!!"
    KM = "Ngh" & ChrW(297) & "a " & ChrW(272) & ChrW(7865) & "p Trai"
    KT = MyUniMsgBox(KM, Str1, 3, 111) ''<- Thay doi Tham So Sau no lay ICO Sytem32 cua Win
    If KT = vbYes Then
        MsgBox "Ban Chon Co", , "Thông Báo"
    ElseIf KT = vbCancel Then
        MsgBox "Ban Chon Huy Bo", , "Thông Báo"
    Else
        MsgBox "Ban Chon Khong", , "Thông Báo"
    End If
End Sub


Sub Main2_MyUniMsgBox()
    Dim Str1 As String, KM As String, KT As String
    Str1 = "Written by Hoàng Tr" & ChrW(7885) & "ng Ngh" & ChrW(297) & "a" & vbCrLf _
    & "Gi" & ChrW(7843) & "i Pháp Excel Công C" & ChrW(7909) & " Tuy" & ChrW(7879) _
    & "t V" & ChrW(7901) & "i C" & ChrW(7911) & "a B" & ChrW(7841) & "n !!!"
    KM = "Ngh" & ChrW(297) & "a " & ChrW(272) & ChrW(7865) & "p Trai"
    KT = MyUniMsgBox(KM, Str1, msoAlertIconInfo, 14)
    If KT = vbYes Then
        MsgBox "Ban Chon Co", , "Thông Báo"
    Else
        MsgBox "Ban Chon Khong", , "Thông Báo"
    End If
End Sub


Function UniMsgbox(Optional ByVal TieuDe As String = "", Optional ByVal NoiDung As String, _
                   Optional ByVal Buuton As Long, Optional ByVal Icon As Long)
    Rem Cau truc: UniMsgBox [Tieu De], [Noi Dung], [Kieu Nut Lenh], [Kieu Icon]
    If TieuDe = "" Then TieuDe = ("Th" & ChrW(244) & "ng B" & ChrW(225) & "o") ''Thông Báo
    UniMsgbox = MyMsgBox(TieuDe, NoiDung, Buuton, Icon)
End Function


Sub Main_UniMsgbox()
    Dim TB As String, NoiDung As String, x
    TB = "Thông Báo"
    NoiDung = "Ki" & ChrW(7873) & "u M" & ChrW(7841) & "nh" _
                & vbLf & "Tr" & ChrW(226) & "n Tr" & ChrW(7885) & "ng Th" & ChrW(244) & "ng B" & ChrW(225) & "o"
    x = MyUniMsgBox(TB, NoiDung, 3, 111)
    If x = vbYes Then
        MsgBox "Yes"
    ElseIf x = vbNo Then
        MsgBox "No"
    Else
        MsgBox "Cancel"
    End If
End Sub

Cảm ơn anh Mạnh! **~**
Anh cho hỏi chỗ nào để thay mấy cái chữ Yes/No/Cancel thành ... A/B/C vậy... anh bôi đỏ chỗ đó giúp em. &&&%$R
 
Upvote 0
Một .....2.................3................................Run ...........................%#^#$
 
Upvote 0
Một .....2.................3................................Run ...........................%#^#$

Run Main_MyUniMsgBox thấy: có 3 nút có/không/hủy bỏ
anh Mạnh cho hỏi 3 chữ có/không/hủy bỏ nó nằm ở đâu, nếu thay 3 nút đó thành: A/B/C thì chỉnh ở chỗ nào thế anh?
Cảm ơn.
 
Lần chỉnh sửa cuối:
Upvote 0
[QUOTE = củ lạc; 768.644] anh [QUOTE = lạc củ; 768,644] anh MạnhMạnh ơi !!!!!!!!!!!!!!!!!! ơi !!!!!!!!!!!!!!!!!! ,,,,,,,[/QUOTE] [/QUOTE]
Mã:
'---------------------------------------------------------------------------------------' Ten Module    : MsgBoxTV
' Tac gia     : Hoang Trong Nghia
' Ngày        : 2/17/2016
' Chu thich  : Ham UniBox Tieng Viet
'---------------------------------------------------------------------------------------
Option Explicit
'******************************************************************************************************************************
'-----------------------------------------------------------------------------------------------------
'--Cau truc: UniBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
'-----------------------------------------------------------------------------------------------------
'******************************************************************************************************************************
#If VBA7 Or Win64 Then  'Office 64-bit
Private hHook As LongPtr
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As _
                Long
Private Declare PtrSafe Function SetDlgItemText Lib "user32" Alias _
                "SetDlgItemTextW" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As LongPtr, _
                ByVal lpString As String) As Long
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias _
                "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal _
                hmod As LongPtr, ByVal dwThreadId As LongPtr) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal _
                hHook As LongPtr) As Long
#Else   ' Office 32-bit
Private hHook As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetDlgItemText Lib "user32" Alias _
                "SetDlgItemTextW" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal _
                lpString As String) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
                "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod _
                As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As _
                Long) As Long
#End If
'******************************************************************************************************************************
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
'--------------------------------------------------------------------------
Private Const IdOK = 1
Private Const IdCancel = 2
Private Const IdAbort = 3
Private Const IdRetry = 4
Private Const IdIgnore = 5
Private Const IdYes = 6
Private Const IdNo = 7
Private Const IdYesAll = 8
'--------------------------------------------------------------------------
Private StrOK As String
Private StrCancel As String
Private StrAbort As String
Private StrRetry As String
Private StrIgnore As String
Private StrYes As String
Private StrNo As String
Private StrYesAll As String
'******************************************************************************************************************************
Private Function MsgBoxHookProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal _
                                lParam As Long) As Long
    If lMsg = HCBT_ACTIVATE Then
        'De biet Charcode, dung ham ASCW("KyTu")
        StrOK = "Ch" & ChrW(7845) & "p nh" & ChrW(7853) & "n"      'Chap nhan
        StrCancel = "&H" & ChrW$(7911) & "y b" & ChrW$(7887)        'Huy bo
        StrAbort = "&H" & ChrW$(7911) & "y ngang"                  'Huy ngang
        StrRetry = "&Th" & ChrW$(7917) & " l" & ChrW$(7841) & "i"   'Thu lai
        StrIgnore = "&B" & ChrW$(7887) & " qua"                  'Bo qua
        StrYes = "&Có"                                            'Co
        StrNo = "&Không"                                            'Khong
        StrYesAll = "Có &t" & ChrW$(7845) & "t c" & ChrW$(7843)  'Co tat ca
        '--------------------------------------------------------------------------
        SetDlgItemText wParam, IdOK, StrConv(StrOK, vbUnicode)
        SetDlgItemText wParam, IdCancel, StrConv(StrCancel, vbUnicode)
        SetDlgItemText wParam, IdAbort, StrConv(StrAbort, vbUnicode)
        SetDlgItemText wParam, IdRetry, StrConv(StrRetry, vbUnicode)
        SetDlgItemText wParam, IdIgnore, StrConv(StrIgnore, vbUnicode)
        SetDlgItemText wParam, IdYes, StrConv(StrYes, vbUnicode)
        SetDlgItemText wParam, IdNo, StrConv(StrNo, vbUnicode)
        SetDlgItemText wParam, IdYesAll, StrConv(StrYesAll, vbUnicode)
        '--------------------------------------------------------------------------
        UnhookWindowsHookEx hHook
    End If
    MsgBoxHookProc = False
End Function
'******************************************************************************************************************************
Function UniBox(Optional ByVal MsgTitle_Tieu_De As String = "", Optional MsgText_Noi_Dung As String, Optional _
            msgButtonType As MsoAlertButtonType, Optional msgIconType As MsoAlertIconType, _
            Optional msgDefaultType As MsoAlertDefaultType) As VbMsgBoxResult
    '-----------------------------------------------------------------------------------------------------
    '--Cau truc: UniBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
    '-----------------------------------------------------------------------------------------------------
    If Len(MsgTitle_Tieu_De) = 0 Then MsgTitle_Tieu_De = "Thông báo"
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, _
            GetCurrentThreadId)
    On Error Resume Next
    UniBox = Assistant.DoAlert(MsgTitle_Tieu_De, MsgText_Noi_Dung, msgButtonType, msgIconType, _
            msgDefaultType, msoAlertCancelDefault, False)
    If Err.Number Then
        Err.Clear
        UniBox = Assistant.DoAlert(MsgTitle_Tieu_De, MsgText_Noi_Dung, msgButtonType, _
                msgIconType, msoAlertDefaultFirst, msoAlertCancelDefault, False)
    End If
End Function
'******************************************************************************************************************************
Function UniInputBox(Optional ByVal MsgTitle_Tieu_De As String = "", Optional MsgText_Noi_Dung As String, _
            Optional msgButtonType As MsoAlertButtonType, Optional msgIconType As _
            MsoAlertIconType, Optional msgDefaultType As MsoAlertDefaultType) As String
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, _
            GetCurrentThreadId)
    Dim con As String
Rep:
    On Error Resume Next
    UniInputBox = Application.InputBox(MsgText_Noi_Dung, MsgTitle_Tieu_De)
    If Len(UniInputBox) = 0 Then GoTo Err
    Exit Function
Err:
    UniBox "Thông báo", "Kh" & ChrW(244) & "ng th" & ChrW(7875) & " b" & _
            ChrW(7887) & " tr" & ChrW(7889) & "ng n" & ChrW(7897) & "i dung."
    GoTo Rep
End Function


Sub dfgfdg()
UniBox , "Noi DUng"
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0
Mã:
'---------------------------------------------------------------------------------------' Ten Module    : MsgBoxTV
' Tac gia     : Hoang Trong Nghia
' Ngày        : 2/17/2016
' Chu thich  : Ham UniBox Tieng Viet
'---------------------------------------------------------------------------------------
Option Explicit
'******************************************************************************************************************************
'-----------------------------------------------------------------------------------------------------
'--Cau truc: UniBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
'-----------------------------------------------------------------------------------------------------
'******************************************************************************************************************************
#If VBA7 Or Win64 Then  'Office 64-bit
Private hHook As LongPtr
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As _
                Long
Private Declare PtrSafe Function SetDlgItemText Lib "user32" Alias _
                "SetDlgItemTextW" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As LongPtr, _
                ByVal lpString As String) As Long
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias _
                "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As LongPtr, ByVal _
                hmod As LongPtr, ByVal dwThreadId As LongPtr) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal _
                hHook As LongPtr) As Long
#Else   ' Office 32-bit
Private hHook As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetDlgItemText Lib "user32" Alias _
                "SetDlgItemTextW" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal _
                lpString As String) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
                "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod _
                As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As _
                Long) As Long
#End If
'******************************************************************************************************************************
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
'--------------------------------------------------------------------------
Private Const IdOK = 1
Private Const IdCancel = 2
Private Const IdAbort = 3
Private Const IdRetry = 4
Private Const IdIgnore = 5
Private Const IdYes = 6
Private Const IdNo = 7
Private Const IdYesAll = 8
'--------------------------------------------------------------------------
Private StrOK As String
Private StrCancel As String
Private StrAbort As String
Private StrRetry As String
Private StrIgnore As String
Private StrYes As String
Private StrNo As String
Private StrYesAll As String
'******************************************************************************************************************************
Private Function MsgBoxHookProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal _
                                lParam As Long) As Long
    If lMsg = HCBT_ACTIVATE Then
        'De biet Charcode, dung ham ASCW("KyTu")
[B]        StrOK = "Ch" & ChrW(7845) & "p nh" & ChrW(7853) & "n"      'Chap nhan
        StrCancel = "&H" & ChrW$(7911) & "y b" & ChrW$(7887)        'Huy bo
        StrAbort = "&H" & ChrW$(7911) & "y ngang"                  'Huy ngang
        StrRetry = "&Th" & ChrW$(7917) & " l" & ChrW$(7841) & "i"   'Thu lai
        StrIgnore = "&B" & ChrW$(7887) & " qua"                  'Bo qua
        StrYes = "&Có"                                            'Co
        StrNo = "&Không"                                            'Khong
        StrYesAll = "Có &t" & ChrW$(7845) & "t c" & ChrW$(7843)  'Co tat ca[/B]
        '--------------------------------------------------------------------------
        SetDlgItemText wParam, IdOK, StrConv(StrOK, vbUnicode)
        SetDlgItemText wParam, IdCancel, StrConv(StrCancel, vbUnicode)
        SetDlgItemText wParam, IdAbort, StrConv(StrAbort, vbUnicode)
        SetDlgItemText wParam, IdRetry, StrConv(StrRetry, vbUnicode)
        SetDlgItemText wParam, IdIgnore, StrConv(StrIgnore, vbUnicode)
        SetDlgItemText wParam, IdYes, StrConv(StrYes, vbUnicode)
        SetDlgItemText wParam, IdNo, StrConv(StrNo, vbUnicode)
        SetDlgItemText wParam, IdYesAll, StrConv(StrYesAll, vbUnicode)
        '--------------------------------------------------------------------------
        UnhookWindowsHookEx hHook
    End If
    MsgBoxHookProc = False
End Function
'******************************************************************************************************************************
Function UniBox(Optional ByVal MsgTitle_Tieu_De As String = "", Optional MsgText_Noi_Dung As String, Optional _
            msgButtonType As MsoAlertButtonType, Optional msgIconType As MsoAlertIconType, _
            Optional msgDefaultType As MsoAlertDefaultType) As VbMsgBoxResult
    '-----------------------------------------------------------------------------------------------------
    '--Cau truc: UniBox TieuDe (bat buoc), [NoiDung], [KieuNutLenh], [KieuIcon], [KieuNutLenhMacDinh]
    '-----------------------------------------------------------------------------------------------------
    If Len(MsgTitle_Tieu_De) = 0 Then MsgTitle_Tieu_De = "Thông báo"
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, _
            GetCurrentThreadId)
    On Error Resume Next
    UniBox = Assistant.DoAlert(MsgTitle_Tieu_De, MsgText_Noi_Dung, msgButtonType, msgIconType, _
            msgDefaultType, msoAlertCancelDefault, False)
    If Err.Number Then
        Err.Clear
        UniBox = Assistant.DoAlert(MsgTitle_Tieu_De, MsgText_Noi_Dung, msgButtonType, _
                msgIconType, msoAlertDefaultFirst, msoAlertCancelDefault, False)
    End If
End Function
'******************************************************************************************************************************
Function UniInputBox(Optional ByVal MsgTitle_Tieu_De As String = "", Optional MsgText_Noi_Dung As String, _
            Optional msgButtonType As MsoAlertButtonType, Optional msgIconType As _
            MsoAlertIconType, Optional msgDefaultType As MsoAlertDefaultType) As String
    hHook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHookProc, 0, _
            GetCurrentThreadId)
    Dim con As String
Rep:
    On Error Resume Next
    UniInputBox = Application.InputBox(MsgText_Noi_Dung, MsgTitle_Tieu_De)
    If Len(UniInputBox) = 0 Then GoTo Err
    Exit Function
Err:
    UniBox "Thông báo", "Kh" & ChrW(244) & "ng th" & ChrW(7875) & " b" & _
            ChrW(7887) & " tr" & ChrW(7889) & "ng n" & ChrW(7897) & "i dung."
    GoTo Rep
End Function


Sub dfgfdg()
UniBox , "Noi DUng"
End Sub

Khó hiểu quá, mong bạn giải thích thêm cho:
Bài 14 không có cái đoạn bôi đậm vậy tại sao vẫn ra được các nút có dấu tiếng Việt ,

Cảm ơn
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom