Hello Gert,
There have been several replies already with suggestions and some conversion
macros.
Although I think using the word NEDERLANDS was worth trying, your experience
already says that it has not helped solve the problem. I do not know exactly
how Word determines the character set of a data file, but I suspect that
a. it uses a standard Win32 routine that takes a piece of text and tries to
determine the character set/locale
b. that routine is easily confused, particularly when there are a lot of
delimiter characters in the text.
Just in case you cannot see the suggestions, here they are again:
From Cindy Meister:
-----------------------------------------------------------------
Hi Gert,
I have a couple of thoughts following up on Peter's response:
1. If you rename this to a *.txt file does it work? (Note that I'm not
suggesting you do so permanently, but this will give us a better idea of
what process is connecting to the data)
2. How about using *.prn, instead?
3. If you activate Tools/OPtions/Confirm conversions on open you can
choose to use OLE DB, Word's internal file converter or ODBC to connect.
(ODBC may not be in the list, but activate "Show all" and you can see
it.) Test with these different methods. Does any one of them give you a
better result?
4. Possibly, you could set up a DSN for the ODBC driver to work
specifically with TAB and a different character set if none of the above
help very much. The bigger problem then becomes the distribution of the
DSN.
5. Do you NEED any Asian languages in your work? If not, one could try
deactivating (and uninstalling) any Asian language support for Office
and see if this helps.
Additonal note: It's quite possible that the program creating a *.dat
file did so explicitly for *previous* versions of Office to force Word
to use its internal text converter to open the data source.
Unfortunately, OLE DB does recognize *.dat as something it can work
with, so this "trick" doesn't work with Word 2002 and later.
-----------------------------------------------------------------
From me (but I think you should pursue Cindy's suggestions before trying
this, especially the ODBC ones, and if you do it is worth adding that ODBC
creates a SCHEMA.INI file in the folder containing the .DAT file and that it
is possible to eidt that using e.g. Notepad to specify a character set of
ANSI or OEM. It is also possible to specify a Windows character set number,
but
a. that is an undocumented "feature"
b. any changes in the ODBC Administrator will overwrite acharacter set
number with either ANSI or OEM.
-----------------------------------------------------------------
I think the only option is probably to do a separate conversion of the file
format before you use the
file as a data source. However, this may introduce other problems.
If you convert to another type of encoded text file, as far as I know, the
only text file formats that Word will /always/ recognise correctly are the
Unicode ones, particularly UTF-8, as long as they start with the Unicode
Byte Order Mark (BOM). Although the BOM is strictly speaking optional, both
Notepad (on WIndows 2000 and later) and Word always insert it. However, the
other problem is that Word
always seems to display the Encoding dialog box when the file is Unicode, so
the only thing you really gain by using this approach is that you do not
have to choose the right encoding (as it is already selected), and the
characters should be correct.
If you convert to a Word .doc file, you may encounter performance problems
and (possibly) restrictions on the column count. But otherwise, that is
probably the best option.
To do the conversion, you need a simple macro, but you might need to do more
to cope with different file names and so on.
E.g.
Sub ConvertToUTF8()
' convert to a UTF8 format text file
' Needs error checking etc.
Dim oDoc as Word.Document
' change msoEncodingWestern to be the encoding you need. I think this should
work.
Set oDoc = Documents.Open("the path name of the file you need to
convert.txt", _
False, , False, , , , , , _
wdOpenFormatEncodedText, _
msoEncodingWestern, _
False, False, , True)
' Several of the parameters here are optional or
' irrelevant - you can probably remove the lines from
' ReadOnlyRecommended to SaveAsAOCLetter
oDoc.SaveAs _
FileName:="the path name of the file to convert to.txt", _
FileFormat:=wdFormatUnicodeText, _
AddToRecentFiles:=False, _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCLetter:=False, _
Encoding:=msoEncodingUTF8, _
InsertLineBreaks:=False, _
AllowSubstitutions:=False, _
LineEnding:=wdCRLF
oDoc.Close Savechanges:=False
Set oDoc = Nothing
End Sub
or
Sub ConvertToWord()
' convert to a Word document file
' Needs error checking etc.
Dim oDoc as Word.Document
' change msoEncodingWestern to be the encoding you need. I think this should
work.
Set oDoc = Documents.Open("the path name of the file you need to
convert.txt", _
False, , False, , , , , , _
wdOpenFormatEncodedText, _
msoEncodingWestern, _
False, False, , True)
' Several of the parameters here are optional or
' irrelevant - you can probably remove the lines from
' ReadOnlyRecommended to Encoding
oDoc.SaveAs _
FileName:="the path name of the file to convert to.doc", _
FileFormat:=wdFormatDocument, _
AddToRecentFiles:=False, _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCLetter:=False, _
Encoding:=msoEncodingUTF8, _
InsertLineBreaks:=False, _
AllowSubstitutions:=False, _
LineEnding:=wdCRLF
oDoc.Close Savechanges:=False
Set oDoc = Nothing
End Sub