PDA

View Full Version : Ascii to Unicode in VBA word



shlomiassaf
08-21-2007, 06:03 PM
Hi.

Background:
I have a WinXP which is in hebrew, this means that any Non Unicode program that handels text will use the ASCII chart for hebrew.

As you might know the Ascii chart for hebrew has english letters which have the same value as the ones in the popular Western Europe Ascii chart.

The diffrence is for Chr values above 127, Those are used for hebrew in my Ascii chart and in the Western Europe Ascii Chart they are used for special letteres in Spanish, France, German etc.

I get a text file with a lot of data in CVS format, the text file hold among other thing also the names of people and thier address, I need to take this data and put in in word.

The file is ready and works perfectly except one thing.

The special letters in the word file appears in hebrew and not like they were meny to be.

This is because Windows thinks this file is coded via Hebrew Ascii code because it was not made unicode (I can receive it Unicode)

Basicaly whay I need to do is to covnert the values to unicode and tell VB to take that chr value and put it as unicode but treat the Chr as Western Union ASCII.

Anyone has any idea how to take a string and make it unicode?


For example when I load the TXT file in word then word tells me that this file is non unicode and he thinks it was originally Western Europe and offers me to make it like that, I press OK and I see all the right charecters


Any Help?

PS - Sorry for the long post, had to explain my self clearly.

Oorang
08-30-2007, 08:24 AM
Hmmm well this will convert an ansi file to unicode. Let me know how it goes:
Option Explicit

Public Sub ConvertAnsiiFileToUnicode()
Const TristateUseDefault As Long = -2
Const ForReading As Long = 1
Const lCancelled_c As Long = 0
Dim oFSO As Object
Dim oTS As Object
Dim strFilePath As String
Dim strFileText As String
strFilePath = GetFilePath
If VBA.LenB(strFilePath) = lCancelled_c Then Exit Sub
Set oFSO = VBA.CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile(strFilePath, ForReading, False, TristateUseDefault)
strFileText = oTS.ReadAll
oTS.Close
Set oTS = oFSO.CreateTextFile(strFilePath, True, True)
oTS.Write strFileText
oTS.Close
VBA.MsgBox "File converted.", vbInformation + vbMsgBoxSetForeground, "Operation Complete"
End Sub
Private Function GetFilePath() As String
Dim oFD As Office.FileDialog
Set oFD = Word.Application.FileDialog(msoFileDialogOpen)
If oFD.Show Then GetFilePath = oFD.SelectedItems(1)
End Function