Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2010 - choose codepage when saving as text? Homey Excel Discussion (Misc queries) 0 November 13th 09 12:04 PM
Convert to string help pokdbz Excel Discussion (Misc queries) 1 June 10th 08 04:59 PM
Codepage in Excel 2003 Stephen Eccleston Excel Discussion (Misc queries) 2 April 11th 08 05:45 PM
[VBA] Convert string to Range Denis[_7_] Excel Programming 3 November 30th 06 06:03 PM
How to convert string to date phil Excel Worksheet Functions 2 October 2nd 06 06:01 PM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"