thầy ơi sao khi mình search nó chỉ ra có bài ở trên không có bài ở dưới vậy
thay cho xin doan code do dc ko ạ
Chào bạn bạn lấy code tại đây nhé:
Cam on thay
Ví dụ mình có 1 đoạn giá trị (string) được lấy từ inputbox có tiếng Việt, thầy cho mình xin 1 hàm để msgbox hiện ra câu đó có Tiếng Việt được ko ạ, mình đã copy về và làm và nó vẫn chưa hiện ra tiếng Việt
Chào bạn với msgbox tiếng việt bạn cần thêm API để hiện thị mình sẽ cung cấp đoạn này sau nhé.
cam on thay
Chào bạn bạn xem đoạn code sau nhé.
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function MessageBoxW Lib "user32" (ByVal Hwnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
#Else
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
#End If
'nguồn sưu tầm
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
Sub goidulieu()
Dim s As String
s = "Công ty TNHH Công Ngh" & ChrW(7879) & " Giáo D" & ChrW(7909) & "c Gitiho Vi" & ChrW(7879) & "t Nam"
MsgBoxUni s
End Sub
Function UniVba(TxtUni As String) As String 'chuyen vba sang uni
Dim N, uni1 As String, uni2 As String
If TxtUni = "" Then
UniVba = """"""
Else
TxtUni = TxtUni & " "
If AscW(Left(TxtUni, 1)) < 256 Then UniVba = """"
For N = 1 To Len(TxtUni) - 1
uni1 = Mid(TxtUni, N, 1)
uni2 = AscW(Mid(TxtUni, N + 1, 1))
If AscW(uni1) > 255 And uni2 > 255 Then
UniVba = UniVba & "ChrW(" & AscW(uni1) & ") & "
ElseIf AscW(uni1) > 255 And uni2 < 256 Then
UniVba = UniVba & "ChrW(" & AscW(uni1) & ") & """
ElseIf AscW(uni1) < 256 And uni2 > 255 Then
UniVba = UniVba & uni1 & """ & "
Else
UniVba = UniVba & uni1
End If
Next
If Right(UniVba, 4) = " & """ Then
UniVba = Mid(UniVba, 1, Len(UniVba) - 4)
Else
UniVba = UniVba & """"
End If
End If
End Function
mình đã dán đoạn code đó vào 1 file excel (*.xlsm) mới nhưng khi chạy nó báo lỗi.
Cái đoạn code này:
#If VBA7 Then
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function MessageBoxW Lib "user32" (ByVal Hwnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
#Else
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
#End If
Dán vô đâu thầy ơi
Ý mình muốn là chương trình nó ra 1 bảng thông báo nhập vô 1 câu tiếng Việt và msgbox hiện ra đúng câu Tiêng Việt đó
Chào bạn vậy bạn có thể tham khảo ví dụ sau nhé:
Mình đã tải về và chạy thử
Sub Test2()
Dim MsgText As String, tieude As String
Dim Name As Variant
MsgText = UniConvert("Nhaapj teen vafo ddaay :")
tieude = UniConvert("Dieenx ddanf tuhocvba chafo cacs banj")
Name = Application.InputBox(Prompt:=MsgText, Title:=tieude, Default:="Nguyen Van A", Type:=2) 'Type:=2 la kieu ky tu Text
If VarType(Name) = 11 Then Exit Sub 'Nguoi dung an vao nut Cancel
'Cac ban tham khao them o day:
' https://tuhocvba.net/threads/cung-tim...
MsgBox Name
End Sub
Chào bạn bạn để msgboxuni.. nó sẽ chạy bạn nhé.
Thầy cho mình xin 1 đoạn code hoàn chỉnh với ý định: Xuất hiện 1 hộp thoại inputbox cho người nhập dữ liệu vào (Tiếng Việt) và xuất bảng thông báo có câu Tiếng Việt đó. Mình đã thử các cách ở trên mà khi xuất msgboxuni nó vẫn báo lỗi, msgboxuni chỉ thông báo đúng khi câu đó là dữ liệu trong ô trên sheet hoặc mình gõ trước kiểu này (Dieenx ddanf tuhocvba chafo cacs banj)thôi ạ
Chào bạn, bạn thực hiện như sau nhé.
Sub Test2()
Dim MsgText As String, tieude As String
Dim Name As Variant
MsgText = UniConvert("Nhaapj teen vafo ddaay :")
tieude = UniConvert("Dieenx ddanf tuhocvba chafo cacs banj")
Name = Application.InputBox(Prompt:=MsgText, Title:=tieude, Default:="Nguyen Van A", Type:=2) 'Type:=2 la kieu ky tu Text
If VarType(Name) = 11 Then Exit Sub 'Nguoi dung an vao nut Cancel
'Cac ban tham khao them o day:
' https://tuhocvba.net/threads/cung-tim... ' thay đổi code thành MsgBoxUnicode
MsgBoxUnicode Name
End Sub
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function MessageBoxW Lib "user32" (ByVal hwnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Function UniConvert(text As String, InputMethod As String) As String
Dim VNI_Type, Telex_Type, CharCode, temp, i As Long
UniConvert = text
VNI_Type = Array("a81", "a82", "a83", "a84", "a85", "a61", "a62", "a63", "a64", "a65", "e61", _
"e62", "e63", "e64", "e65", "o61", "o62", "o63", "o64", "o65", "o71", "o72", "o73", "o74", _
"o75", "u71", "u72", "u73", "u74", "u75", "a1", "a2", "a3", "a4", "a5", "a8", "a6", "d9", _
"e1", "e2", "e3", "e4", "e5", "e6", "i1", "i2", "i3", "i4", "i5", "o1", "o2", "o3", "o4", _
"o5", "o6", "o7", "u1", "u2", "u3", "u4", "u5", "u7", "y1", "y2", "y3", "y4", "y5")
Telex_Type = Array("aws", "awf", "awr", "awx", "awj", "aas", "aaf", "aar", "aax", "aaj", "ees", _
"eef", "eer", "eex", "eej", "oos", "oof", "oor", "oox", "ooj", "ows", "owf", "owr", "owx", _
"owj", "uws", "uwf", "uwr", "uwx", "uwj", "as", "af", "ar", "ax", "aj", "aw", "aa", "dd", _
"es", "ef", "er", "ex", "ej", "ee", "is", "if", "ir", "ix", "ij", "os", "of", "or", "ox", _
"oj", "oo", "ow", "us", "uf", "ur", "ux", "uj", "uw", "ys", "yf", "yr", "yx", "yj")
CharCode = Array(ChrW(7855), ChrW(7857), ChrW(7859), ChrW(7861), ChrW(7863), ChrW(7845), ChrW(7847), _
ChrW(7849), ChrW(7851), ChrW(7853), ChrW(7871), ChrW(7873), ChrW(7875), ChrW(7877), ChrW(7879), _
ChrW(7889), ChrW(7891), ChrW(7893), ChrW(7895), ChrW(7897), ChrW(7899), ChrW(7901), ChrW(7903), _
ChrW(7905), ChrW(7907), ChrW(7913), ChrW(7915), ChrW(7917), ChrW(7919), ChrW(7921), ChrW(225), _
ChrW(224), ChrW(7843), ChrW(227), ChrW(7841), ChrW(259), ChrW(226), ChrW(273), ChrW(233), ChrW(232), _
ChrW(7867), ChrW(7869), ChrW(7865), ChrW(234), ChrW(237), ChrW(236), ChrW(7881), ChrW(297), ChrW(7883), _
ChrW(243), ChrW(242), ChrW(7887), ChrW(245), ChrW(7885), ChrW(244), ChrW(417), ChrW(250), ChrW(249), _
ChrW(7911), ChrW(361), ChrW(7909), ChrW(432), ChrW(253), ChrW(7923), ChrW(7927), ChrW(7929), ChrW(7925))
Select Case InputMethod
Case Is = "VNI": temp = VNI_Type
Case Is = "Telex": temp = Telex_Type
End Select
For i = 0 To UBound(CharCode)
UniConvert = Replace(UniConvert, temp(i), CharCode(i))
UniConvert = Replace(UniConvert, UCase(temp(i)), UCase(CharCode(i)))
Next i
End Function
Function MsgBoxUni(ByVal PromptUni As Variant, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal TitleUni As Variant = vbNullString) As VbMsgBoxResult
'Function MsgBoxUni(ByVal PromptUni As Variant, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal TitleUni As Variant, Optional HelpFile, Optional Context) As VbMsgBoxResult
'BStrMsg,BStrTitle : La chuoi Unicode
Dim BStrMsg, BStrTitle
'Hàm StrConv Chuyen chuoi ve ma Unicode
BStrMsg = StrConv(PromptUni, vbUnicode)
BStrTitle = StrConv(TitleUni, vbUnicode)
MsgBoxUni = MessageBoxW(GetActiveWindow, BStrMsg, BStrTitle, Buttons)
End Function
Sub Nhap_vao_xuat_ra_tieng_Viet()
Dim MsgText As String, tieude As String
Dim Name As Variant
MsgText = UniConvert("Nhaajp teen vafo ddaay :", "Telex")
tieude = UniConvert("Dieexn ddafn tuhocvba chafo casc bajn", "Telex")
Name = Application.InputBox(Prompt:=MsgText, Title:=tieude, Default:="", Type:=2)
If VarType(Name) = 11 Then Exit Sub
MsgBoxUni Name
End Sub
Đã chạy và thành công. Cám ơn thầy