tranvantuxaydung
Thành viên mới

- Tham gia
- 19/2/20
- Bài viết
- 2
- Được thích
- 0
Đơn giản nhất là bạn vào Word viết và record macro là được.Trong sách của anh Hướng có soạn thảo tiếng việt trong code và trong Msgbox như hình :
Vậy xin hỏi làm cách nào để có thể thực hiện được như hình trong sách.
View attachment 233457
View attachment 233460
'MsgBox Tiêìng Viêòt
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As Long
Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal CodeNo As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal ParenthWnd As LongPtr, ByVal ChildhWnd As LongPtr, ByVal ClassName As String, ByVal Caption As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As Long
Private Declare PtrSafe Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As Any) As Long
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hWnd As LongPtr, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare PtrSafe Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare PtrSafe Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare PtrSafe Function DestroyCursor Lib "user32" (ByVal hCursor As Long) As Boolean
Private Declare PtrSafe Function IsWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare PtrSafe Function MessageBoxW Lib "user32.dll" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long
Private Declare PtrSafe Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal i As Long, ByVal U As Long, ByVal S As Long, ByVal c As Long, ByVal OP As Long, ByVal cp As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Declare PtrSafe Function SetWindowTextW Lib "user32" (ByVal hWnd As LongPtr, ByVal lpString As LongPtr) As Long
Private Declare PtrSafe Function MsgBoxTimeoutW Lib "user32" Alias "MessageBoxTimeoutW" (ByVal hWnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As VbMsgBoxStyle, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
#Else
Private Declare Function MsgBoxTimeoutW Lib "user32" Alias "MessageBoxTimeoutW" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As VbMsgBoxStyle, ByVal wlange As Long, ByVal dwTimeout 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 CallNextHookEx Lib "user32" ( ByVal hHook As Long, ByVal CodeNo As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" ( ByVal hHook As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( ByVal ParenthWnd As Long, ByVal ChildhWnd As Long, ByVal className As String, ByVal Caption As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" ( ByVal lpFileName As Any) As Long
Private Declare Function SetWindowPos Lib "user32" ( ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" ( ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32" ( ByVal hwnd As Long) As Long
Private Declare Function DestroyCursor Lib "user32" ( ByVal hCursor As Long) As Boolean
Private Declare Function IsWindow Lib "user32" ( ByVal hwnd As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" ( ByVal hObject As Long) As Long
Private Declare Function MessageBoxW Lib "user32.dll" ( ByVal hwnd As Long, ByVal lpText As Long, ByVal lpCaption As Long, ByVal uType As Long) As Long
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" ( ByVal h As Long, ByVal W As Long, ByVal e As Long, ByVal o As Long, ByVal W As Long, ByVal i As Long, ByVal u As Long, ByVal s As Long, ByVal c As Long, ByVal OP As Long, ByVal CP As Long, ByVal q As Long, ByVal PAF As Long, ByVal f As String) As Long
Private Declare Function SetWindowTextW Lib "user32" ( ByVal hwnd As Long, ByVal lpString As Long) As Long
#End If
Public Type Var64
#If Win64 Then
Long As LongPtr
#Else
Long As Long
#End If
End Type
Public hDlgHook As Var64, hDlgHWnd As Var64
Private Const WM_SETFONT = &H30
Private Const MB_TASKMODAL = &H2000&
Public hFont&
Private Const FONT_FACE = "Tahoma"
Sub Kieudulieu()
Dim Ten As String 'Khai báo tên ngýõÌi là chuôÞi
Dim TUOi As Integer 'Khai báo tuôÒi là sôì nguyên
Dim Chieucao As Single 'Khai báo chiêÌu cao là sôì thâòp phân
TUOi = 22 'Gán týÌng giá triò Tuoi, Chieucao, Ten
Chieucao = 1.74
Ten = "NguyêÞn Vãn Ðýìc"
Alert VietnameseUTF8("Hoò và tên: " & Ten & Chr(13) & "TuôÒi là " & TUOi & _
" tuôÒi" & Chr(13) & "ChiêÌu Cao " & Chieucao & " (m)", True)
End Sub
' _,
' ___ _ _ _ ___(_)
'/ __| / \ | \| | _ | |
'\__ \/ \ \| \\ | _ \ |
'|___/_/ \_|_|\_|___/_|
'
' Last Edit: 09/03/2020 17:01
Public Function Alert(ByVal Prompt As String, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal Title As String = "Thông báo", Optional ByVal hWnd& = &H0, Optional ByVal Timeout& = 10) As VbMsgBoxResult
If Timeout <= 0 Then Timeout = 3600
#If Win64 Then
hDlgHook.Long = SetWindowsHookEx(5, AddressOf HookProcMsgBox, Application.HinstancePtr, GetCurrentThreadId())
#Else
hDlgHook.Long = SetWindowsHookEx(5, AddressOf HookProcMsgBox, Application.hInstance, GetCurrentThreadId())
#End If
Alert = MsgBoxTimeoutW(hWnd, VBA.StrConv(Prompt, 64), VBA.StrConv(Title, 64), Buttons Or MB_TASKMODAL, 0&, Timeout * 1000)
DeleteObject hFont
End Function
' _,
' ___ _ _ _ ___(_)
'/ __| / \ | \| | _ | |
'\__ \/ \ \| \\ | _ \ |
'|___/_/ \_|_|\_|___/_|
'
#If Win64 Then
Private Function HookProcMsgBox&(ByVal nCode&, ByVal wParam^, ByVal lParam^)
#Else
Private Function HookProcMsgBox&(ByVal nCode&, ByVal wParam&, ByVal lParam&)
#End If
Dim hStatic1 As Var64, hStatic2 As Var64, hButton As Var64, nCaption As String, lCaption As String
HookProcMsgBox = CallNextHookEx(hDlgHook.Long, nCode, wParam, lParam)
If nCode = 5 Then
hFont = CreateFont(13, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, FONT_FACE)
hStatic1.Long = FindWindowEx(wParam, 0&, "Static", VBA.vbNullString)
hStatic2.Long = FindWindowEx(wParam, hStatic1.Long, "Static", VBA.vbNullString)
hDlgHWnd.Long = wParam
Call SetWindowPos(hDlgHWnd.Long, -1, 0, 0, 0, 0, &H2 Or &H1)
If hStatic2.Long = 0 Then hStatic2.Long = hStatic1.Long
SendMessage hStatic2.Long, WM_SETFONT, hFont, ByVal 1&
'--------------------------------------
nCaption = "&X" & VBA.ChrW$(225) & "c nh" & VBA.ChrW$(226) & "n"
lCaption = "OK": GoSub Send
nCaption = "&C" & VBA.ChrW$(243)
lCaption = "&Yes": GoSub Send
nCaption = "&Kh" & VBA.ChrW$(244) & "ng"
lCaption = "&No": GoSub Send
nCaption = "&H" & VBA.ChrW$(7911) & "y"
lCaption = "Cancel": GoSub Send
nCaption = "&Th" & VBA.ChrW$(7917) & " l" & VBA.ChrW$(7841) & "i"
lCaption = "&Retry": GoSub Send
nCaption = "&B" & VBA.ChrW$(7887) & " qua"
lCaption = "&Ignore": GoSub Send
nCaption = "H" & VBA.ChrW$(7911) & "&y b" & VBA.ChrW$(7887)
lCaption = "&Abort": GoSub Send
nCaption = "Tr" & VBA.ChrW$(7907) & " &gi" & VBA.ChrW$(250) & "p"
lCaption = "Help": GoSub Send
'--------------------------------------
UnhookWindowsHookEx hDlgHook.Long
End If
Exit Function
Send:
hButton.Long = FindWindowEx(wParam, 0&, "Button", lCaption)
SendMessage hButton.Long, WM_SETFONT, hFont, 0
SetWindowTextW hButton.Long, StrPtr(nCaption)
Return
End Function
'---------------------------------------------
' ChuyêÒn ðôÒi Tiêìng viêòt giýÞa Unicode và UTF-8
' Last Edit: 12/03/2020 15:16
Public Function VietnameseUTF8(ByVal Text As String, Optional ByVal Reverse As Boolean) As String
Dim Utf8 As Variant, Char As Variant, i As Long
'' Const Acute = "ì"
'' Const graveAccent = "Ì"
'' Const questionMark = "Ò"
'' Const tilde = "Þ"
'' Const Dot = "ò"
'' "Á á à À í Í é É È è ó Ó Ú ú ù Ù ê Ê â Â ô Ô Ð "
'' "ã Ã ý Ý õ Õ Yì yì ð"
Char = VBA.Array(ChrW(195), ChrW(227), ChrW(258), ChrW(259), ChrW(204), ChrW(236), ChrW(210), ChrW(242), ChrW(213), ChrW(245), _
ChrW(7854), ChrW(7855), ChrW(7856), ChrW(7857), ChrW(7858), ChrW(7859), ChrW(7860), ChrW(7861), ChrW(7862), ChrW(7863), _
ChrW(7844), ChrW(7845), ChrW(7846), ChrW(7847), ChrW(7848), ChrW(7849), ChrW(7850), ChrW(7851), ChrW(7852), ChrW(7853), _
ChrW(7870), ChrW(7871), ChrW(7872), ChrW(7873), ChrW(7874), ChrW(7875), ChrW(7876), ChrW(7877), ChrW(7878), ChrW(7879), _
ChrW(7888), ChrW(7889), ChrW(7890), ChrW(7891), ChrW(7892), ChrW(7893), ChrW(7894), ChrW(7895), ChrW(7896), ChrW(7897), _
ChrW(7898), ChrW(7899), ChrW(7900), ChrW(7901), ChrW(7902), ChrW(7903), ChrW(7904), ChrW(7905), ChrW(7906), ChrW(7907), _
ChrW(7912), ChrW(7913), ChrW(7914), ChrW(7915), ChrW(7916), ChrW(7917), ChrW(7918), ChrW(7919), ChrW(7920), ChrW(7921), _
ChrW(7842), ChrW(7843), ChrW(7840), ChrW(7841), ChrW(7866), ChrW(7867), ChrW(7868), ChrW(7869), ChrW(7864), ChrW(7865), _
ChrW(7880), ChrW(7881), ChrW(296), ChrW(297), ChrW(7882), ChrW(7883), ChrW(7886), ChrW(7887), ChrW(7884), ChrW(7885), _
ChrW(7910), ChrW(7911), ChrW(360), ChrW(361), ChrW(7908), ChrW(7909), _
ChrW(7922), ChrW(7923), ChrW(7926), ChrW(7927), ChrW(7928), ChrW(7929), ChrW(7924), ChrW(7925), ChrW(273))
Utf8 = VBA.Array("AÞ", "aÞ", "Ã", "ã", "IÌ", "iÌ", "OÌ", "oÌ", "OÞ", "oÞ", _
"Ãì", "ãì", "ÃÌ", "ãÌ", "ÃÒ", "ãÒ", "ÃÞ", "ãÞ", "Ãò", "ãò", _
"Âì", "âì", "ÂÌ", "âÌ", "ÂÒ", "âÒ", "ÂÞ", "âÞ", "Âò", "âò", _
"Êì", "êì", "ÊÌ", "êÌ", "ÊÒ", "êÒ", "ÊÞ", "êÞ", "Êò", "êò", _
"Ôì", "ôì", "ÔÌ", "ôÌ", "ÔÒ", "ôÒ", "ÔÞ", "ôÞ", "Ôò", "ôò", _
"Õì", "õì", "ÕÌ", "õÌ", "ÕÒ", "õÒ", "ÕÞ", "õÞ", "Õò", "õò", _
"Ýì", "ýì", "ÝÌ", "ýÌ", "ÝÒ", "ýÒ", "ÝÞ", "ýÞ", "Ýò", "ýò", _
"AÒ", "aÒ", "Aò", "aò", "EÒ", "eÒ", "EÞ", "eÞ", "Eò", "eò", _
"IÒ", "iÒ", "IÞ", "iÞ", "Iò", "iò", "OÒ", "oÒ", "Oò", "oò", _
"UÒ", "uÒ", "UÞ", "uÞ", "Uò", "uò", _
"YÌ", "yÌ", "YÒ", "yÒ", "YÞ", "yÞ", "Yò", "yò", "ð")
If Reverse Then
For i = UBound(Char) To LBound(Char) Step -1: Text = VBA.Replace(Text, Utf8(i), Char(i)): Next i
Char = VBA.Array(ChrW(221), ChrW(253), ChrW(431), ChrW(432), ChrW(416), ChrW(417))
Utf8 = VBA.Array("Yì", "yì", "Ý", "ý", "Õ", "õ")
For i = UBound(Char) To LBound(Char) Step -1: Text = VBA.Replace(Text, Utf8(i), Char(i)): Next i
Else
For i = LBound(Char) To UBound(Char)
If "Ýì" = Utf8(i) Then
Text = VBA.Replace(Text, ChrW(253), "yì")
Text = VBA.Replace(Text, ChrW(221), "Yì")
End If
Text = VBA.Replace(Text, Char(i), Utf8(i))
Next i
Text = VBA.Replace(Text, ChrW(416), "Õ")
Text = VBA.Replace(Text, ChrW(417), "õ")
Text = VBA.Replace(Text, ChrW(431), "Ý")
Text = VBA.Replace(Text, ChrW(432), "ý")
End If
VietnameseUTF8 = Text
Erase Char: Erase Utf8
End Function
Khiếp thế.
Người ta chỉ có hỏi làm sao viết được như hình chụp trong sách thôi.
Siêu siêu đơn giản là thiết lập font trong VBE là loại font ABC.
View attachment 233464
View attachment 233465
Còn msgbox thì trong sách có bài chi tiết, thớt chưa có mò tới. Kèm theo sách bán là có tặng File minh họa cụ tỉ rồi.
----------------------------Cảm ơn, đã tìm thấy code trong file excel ví dụ rồi !
' +---------------+-------------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
' | Name | Required/Optional | Data type | Description |
' +---------------+-------------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
' | What | Required | Variant | The string that you want Microsoft Excel to search for. |
' | Replacement | Required | Variant | The replacement string. |
' | LookAt | Optional | Variant | Can be one of the following XlLookAt constants: xlWhole or xlPart. |
' | SearchOrder | Optional | Variant | Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns. |
' | MatchCase | Optional | Variant | True to make the search case-sensitive. |
' | MatchByte | Optional | Variant | You can use this argument only if you have selected or installed double-byte language support in Microsoft Excel. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents. |
' | SearchFormat | Optional | Variant | The search format for the method. |
' | ReplaceFormat | Optional | Variant | The replace format for the method. |
' +---------------+-------------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Thử sửa hết declare thành declare PtrSafe, long thành longptr hết xem sao.Xin các AE trong hội giúp đỡ tôi hàm chuyển đổi font để hiện trên dòng thông báo trong win 10, 11 64bit. Số là, trước đây, tôi cũng có hàm này (cóp nhặt được trên giaiphapexcel) viết dùng trên win 32bit nhưng tôi vẫn dùng được trên win7, 64bit (có thể win7 nó chưa bắt lỗi chặt chẽ), nhưng từ khi chuyển sang win10 hay win11 64bit nó gây lỗi không dùng được........Code cũ viết trên 32 bit tôi đưa lên đây, nhờ các ACE giúp đỡ sửa giúp chuyển từ 32bit qua 64bit dùng được ạ:
Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function MessageBoxW Lib "user32" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Function MsgBoxUni(ByVal PromptUni As Variant, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal TitleUni As Variant = vbNullString) As VbMsgBoxResult
Dim BStrMsg, BStrTitle
BStrMsg = StrConv(PromptUni, vbUnicode)
BStrTitle = StrConv(TitleUni, vbUnicode)
MsgBoxUni = MessageBoxW(GetActiveWindow, BStrMsg, BStrTitle, Buttons)
End Function
Function VNItoUNICODE(vnstr As String)
Dim C As String, i As Integer
Dim db As Boolean
For i = 1 To Len(vnstr)
db = False
If i < Len(vnstr) Then
C = Mid(vnstr, i + 1, 1)
If C = "ù" Or C = "ø" Or C = "û" Or C = "õ" Or C = "ï" Or _
C = "ê" Or C = "é" Or C = "è" Or C = "ú" Or C = "ü" Or C = "ë" Or _
C = "â" Or C = "á" Or C = "à" Or C = "å" Or C = "ã" Or C = "ä" Or _
C = "Ù" Or C = "Ø" Or C = "Û" Or C = "Õ" Or C = "Ï" Or _
C = "Ê" Or C = "É" Or C = "È" Or C = "Ú" Or C = "Ü" Or C = "Ë" Or _
C = "Â" Or C = "Á" Or C = "À" Or C = "Å" Or C = "Ã" Or C = "Ä" Then db = True
End If
If db Then
C = Mid(vnstr, i, 2)
Select Case C
Case "aù": C = ChrW$(225)
Case "aø": C = ChrW$(224)
Case "aû": C = ChrW$(7843)
Case "aõ": C = ChrW$(227)
Case "aï": C = ChrW$(7841)
Case "aê": C = ChrW$(259)
Case "aé": C = ChrW$(7855)
Case "aè": C = ChrW$(7857)
Case "aú": C = ChrW$(7859)
Case "aü": C = ChrW$(7861)
Case "aë": C = ChrW$(7863)
Case "aâ": C = ChrW$(226)
Case "aá": C = ChrW$(7845)
Case "aà": C = ChrW$(7847)
Case "aå": C = ChrW$(7849)
Case "aã": C = ChrW$(7851)
Case "aä": C = ChrW$(7853)
Case "eù": C = ChrW$(233)
Case "eø": C = ChrW$(232)
Case "eû": C = ChrW$(7867)
Case "eõ": C = ChrW$(7869)
Case "eï": C = ChrW$(7865)
Case "eâ": C = ChrW$(234)
Case "eá": C = ChrW$(7871)
Case "eà": C = ChrW$(7873)
Case "eå": C = ChrW$(7875)
Case "eã": C = ChrW$(7877)
Case "eä": C = ChrW$(7879)
Case "où": C = ChrW$(243)
Case "oø": C = ChrW$(242)
Case "oû": C = ChrW$(7887)
Case "oõ": C = ChrW$(245)
Case "oï": C = ChrW$(7885)
Case "oâ": C = ChrW$(244)
Case "oá": C = ChrW$(7889)
Case "oà": C = ChrW$(7891)
Case "oå": C = ChrW$(7893)
Case "oã": C = ChrW$(7895)
Case "oä": C = ChrW$(7897)
Case "ôù": C = ChrW$(7899)
Case "ôø": C = ChrW$(7901)
Case "ôû": C = ChrW$(7903)
Case "ôõ": C = ChrW$(7905)
Case "ôï": C = ChrW$(7907)
Case "uù": C = ChrW$(250)
Case "uø": C = ChrW$(249)
Case "uû": C = ChrW$(7911)
Case "uõ": C = ChrW$(361)
Case "uï": C = ChrW$(7909)
Case "öù": C = ChrW$(7913)
Case "öø": C = ChrW$(7915)
Case "öû": C = ChrW$(7917)
Case "öõ": C = ChrW$(7919)
Case "öï": C = ChrW$(7921)
Case "yù": C = ChrW$(253)
Case "yø": C = ChrW$(7923)
Case "yû": C = ChrW$(7927)
Case "yõ": C = ChrW$(7929)
Case "AÙ": C = ChrW$(193)
Case "AØ": C = ChrW$(192)
Case "AÛ": C = ChrW$(7842)
Case "AÕ": C = ChrW$(195)
Case "AÏ": C = ChrW$(7840)
Case "AÊ": C = ChrW$(258)
Case "AÉ": C = ChrW$(7854)
Case "AÈ": C = ChrW$(7856)
Case "AÚ": C = ChrW$(7858)
Case "AÜ": C = ChrW$(7860)
Case "AË": C = ChrW$(7862)
Case "AÂ": C = ChrW$(194)
Case "AÁ": C = ChrW$(7844)
Case "AÀ": C = ChrW$(7846)
Case "AÅ": C = ChrW$(7848)
Case "AÃ": C = ChrW$(7850)
Case "AÄ": C = ChrW$(7852)
Case "EÙ": C = ChrW$(201)
Case "EØ": C = ChrW$(200)
Case "EÛ": C = ChrW$(7866)
Case "EÕ": C = ChrW$(7868)
Case "EÏ": C = ChrW$(7864)
Case "EÂ": C = ChrW$(202)
Case "EÁ": C = ChrW$(7870)
Case "EÀ": C = ChrW$(7872)
Case "EÅ": C = ChrW$(7874)
Case "EÃ": C = ChrW$(7876)
Case "EÄ": C = ChrW$(7878)
Case "OÙ": C = ChrW$(211)
Case "OØ": C = ChrW$(210)
Case "OÛ": C = ChrW$(7886)
Case "OÕ": C = ChrW$(213)
Case "OÏ": C = ChrW$(7884)
Case "OÂ": C = ChrW$(212)
Case "OÁ": C = ChrW$(7888)
Case "OÀ": C = ChrW$(7890)
Case "OÅ": C = ChrW$(7892)
Case "OÃ": C = ChrW$(7894)
Case "OÄ": C = ChrW$(7896)
Case "ÔÙ": C = ChrW$(7898)
Case "ÔØ": C = ChrW$(7900)
Case "ÔÛ": C = ChrW$(7902)
Case "ÔÕ": C = ChrW$(7904)
Case "ÔÏ": C = ChrW$(7906)
Case "UÙ": C = ChrW$(218)
Case "UØ": C = ChrW$(217)
Case "UÛ": C = ChrW$(7910)
Case "UÕ": C = ChrW$(360)
Case "UÏ": C = ChrW$(7908)
Case "ÖÙ": C = ChrW$(7912)
Case "ÖØ": C = ChrW$(7914)
Case "ÖÛ": C = ChrW$(7916)
Case "ÖÕ": C = ChrW$(7918)
Case "ÖÏ": C = ChrW$(7920)
Case "YÙ": C = ChrW$(221)
Case "YØ": C = ChrW$(7922)
Case "YÛ": C = ChrW$(7926)
Case "YÕ": C = ChrW$(7928)
End Select
Else
C = Mid(vnstr, i, 1)
Select Case C
Case "ô": C = ChrW$(417)
Case "í": C = ChrW$(237)
Case "ì": C = ChrW$(236)
Case "æ": C = ChrW$(7881)
Case "ó": C = ChrW$(297)
Case "ò": C = ChrW$(7883)
Case "ö": C = ChrW$(432)
Case "î": C = ChrW$(7925)
Case "ñ": C = ChrW$(273)
Case "Ô": C = ChrW$(416)
Case "Í": C = ChrW$(205)
Case "Ì": C = ChrW$(204)
Case "Æ": C = ChrW$(7880)
Case "Ó": C = ChrW$(296)
Case "Ò": C = ChrW$(7882)
Case "Ö": C = ChrW$(431)
Case "Î": C = ChrW$(7924)
Case "Ñ": C = ChrW$(272)
End Select
End If
VNItoUNICODE = VNItoUNICODE + C
If db Then i = i + 1
Next i
End Function
Function VNI(strVNI As String)
VNI = VNItoUNICODE(strVNI)
End Function
Đúng là mình đang dùng Office 2016 64bit trên win 11 64bit thì không xài được hàm cũ trên.......Nhưng trước đây dùng Office 2016 64bit trên win 7 64bit thì vẫn xài được.....Do đó, tôi muốn nhờ ACE trong hội giúp đỡ....Để hồi thử xem có dùng được trên máy tôi không: Win 64, Office 32. Vấn đề chắc là do dùng Office 64bit thôi.
Đúng là mình đang dùng Office 2016 64bit trên win 11 64bit thì không xài được hàm cũ trên.......Nhưng trước đây dùng Office 2016 64bit trên win 7 64bit thì vẫn xài được.....Do đó, tôi muốn nhờ ACE trong hội giúp đỡ....
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Public Declare PtrSafe Function MessageBoxW Lib "user32" _
(ByVal hwnd As LongPtr, _
ByVal lpText As LongPtr, _
ByVal lpCaption As LongPtr, _
ByVal wType As Long) As Long
#Else
Private Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function MessageBoxW Lib "user32" _
(ByVal hwnd As Long, _
ByVal lpText As Long, _
ByVal lpCaption As Long, _
ByVal wType As Long) As Long
#End If
Public Function MsgBoxUni(ByVal sMsgUni As String, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal sTitleUni As String = vbNullString) As VbMsgBoxResult
MsgBoxUni = MessageBoxW(GetActiveWindow, StrPtr(sMsgUni), StrPtr(sTitleUni), Buttons)
End Function
Trước khi thử code ongke thì sửa như bài 12 xem dùng được không?Đúng là mình đang dùng Office 2016 64bit trên win 11 64bit thì không xài được hàm cũ trên.......Nhưng trước đây dùng Office 2016 64bit trên win 7 64bit thì vẫn xài được.....Do đó, tôi muốn nhờ ACE trong hội giúp đỡ....
.....nhầm chút.Trước khi thử code ongke thì sửa như bài 12 xem dùng được không?
Tớ đang nghiên cứu tối giản code VBA.
Cách bạn hướng dẫn, tôi đã làm OK rồi. Cám ơn bạn rất nhiều và Maika8008, ongke0711 đã nhiệt tình trợ giúp.Thử sửa hết declare thành declare PtrSafe, long thành longptr hết xem sao.
Vậy có thể hiểu ghi chú của MS chỉ cần khai báo như thế này là sẽ áp dụng được cho office 32, 64 bit từ 2010 trở lên.Thử sửa hết declare thành declare PtrSafe, long thành longptr hết xem sao.