Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert string from one codepage to another
Can someone please give me an advise, how to convert in VBA e.g. this
string "VYé¬TOVµNÖ ¬µSTI SOUD.POPLATKU" which comes from DOS 852 codepage to UTF-8 or to Windows-1250 codepage. I was trying to use e.g. WideCharToMultiByte but I am not experienced enough to do it. BTW the string should correctly look like this "VYÚČTOVÁNÍ ČÁSTI SOUD.POPLATKU". |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert string from one codepage to another
Petr,
StrConv maybe . NickHK "Petr Bazant" wrote in message ups.com... Can someone please give me an advise, how to convert in VBA e.g. this string "VYTOVN STI SOUD.POPLATKU" which comes from DOS 852 codepage to UTF-8 or to Windows-1250 codepage. I was trying to use e.g. WideCharToMultiByte but I am not experienced enough to do it. BTW the string should correctly look like this "VYCTOVN CSTI SOUD.POPLATKU". |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Convert string from one codepage to another
On May 14, 4:45 am, "NickHK" wrote:
Petr, StrConv maybe . NickHK "Petr Bazant" wrote in message ups.com... Can someone please give me an advise, how to convert in VBA e.g. this string "VYTOVN STI SOUD.POPLATKU" which comes from DOS 852codepageto UTF-8 or to Windows-1250codepage. I was trying to use e.g. WideCharToMultiByte but I am not experienced enough to do it. BTW the string should correctly look like this "VYCTOVN CSTI SOUD.POPLATKU". StrConv does not work directly. The solution (not from my head) is: Private Declare Function MultiByteToWideChar Lib "kernel32" ( _ ByVal CodePage As Long, ByVal dwFlags As Long, _ ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _ ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long Private Declare Function WideCharToMultiByte Lib "kernel32" ( _ ByVal CodePage As Long, ByVal dwFlags As Long, _ ByVal lpWideCharStr As String, ByVal cchWideChar As Long, _ ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _ ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long Private Const MB_PRECOMPOSED = &H1 Private Const MY_CP_WINDOWS As Long = 1250 Private Const MY_CP_ISO_1 As Long = 28591 Private Const MY_CP_ISO_2 As Long = 28592 ' ISO Latin-2 Private Const MY_CP_IBM_852 As Long = 852 Private Function StrConvCP1ToCP2(sStr As String, lFromCP As Long, _ Optional lToCP As Long = 0) As String Dim sStrW As String sStrW = String$(2 * Len(sStr), vbNullChar) MultiByteToWideChar lFromCP, MB_PRECOMPOSED, sStr, Len(sStr), _ sStrW, Len(sStr) If lToCP = 0 Then sStr = StrConv(sStrW, vbFromUnicode) Else WideCharToMultiByte lToCP, 0&, sStrW, Len(sStr), sStr, Len(sStr), 0&, 0& End If StrConvCP1ToCP2 = sStr End Function Maybe someone will need it. Sub test() Dim out As String Const src As String = "VYTOVN STI SOUD.POPLATKU" out = StrConvCP1ToCP2(src, 852, 1250) End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2010 - choose codepage when saving as text? | Excel Discussion (Misc queries) | |||
Convert to string help | Excel Discussion (Misc queries) | |||
Codepage in Excel 2003 | Excel Discussion (Misc queries) | |||
[VBA] Convert string to Range | Excel Programming | |||
How to convert string to date | Excel Worksheet Functions |