Mail Merge problem

G

GP

Hi,

I have an application which prepares the datasource file
for me and allows me to download the same on to my
desktop. When I download this file and save it on my PC,
it is always saving the file in unicode format which is
internally causing a problem during Mail Merge. When I
open this datasource file from my word template to merge,
word promts for delimiter and other options. In the
preview window it shows lot of special characters and when
I click on merge it fails and displays field errors.

I was able to resolve this by openning my text file
(Datasource file) and then saving it explicitly. After
this mail merge worked without any problems. Looks like
the format got changed or reset when I did a explicit save.

Note : I have no problems in merging a file in ANSI
format with word. This happens only when the datafile is
in unicode format and only when the file is not saved or
overwritten.

Any thoughts on this..

Thanks
GP
 
P

Peter Jamieson

Do you know exactly which Unicode format is being used? Does your
application give you a choice? Even for a text file, the Unicoce text can be
represented in several different ways (16-bit big-endian Unicode, 16-bit
little-endian, UTF-8 and so on). What's more, a Unicode text file may or may
not start with a "marker character" which tells a Unicode-savvy application
something about the format. Generally speaking I would hope that UTF-8
encoding preceded by the UTF-8 encoded marker character would be correctly
recognised and handled by Word, but there might still be problems because
determining which characters are used for field/record/text delmiter is
logicially distinct from the issue of representation.
 
G

GP

Hi,
Thanks for that info.
My file gets saved in 16-bit little-endian format and as
you just pointed out, Word is unable to recognize field
and record delimiter.

Does word have any settings to handle this format.

Thanks
GP
 
P

Peter Jamieson

Does word have any settings to handle this format.

As far as I know there is nothing you can specify. If you have no control
over the format it's probably best to use a bit of code to automate the
"open and save" operation you are already doing, e.g.

Sub ConvertToUTF8()
' convert to a UTF8 format text file

' Needs error checking etc.
Dim oDoc as Word.Document

' change msoEncodingUnicodeLittleEndian 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, _
msoEncodingUnicodeLittleEndian, _
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 msoEncodingUnicodeLittleEndian 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, , , , , , _
wdOpenFormatUnicodeLittleEndian, _
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

Personally I would be interested to know whether or not the Little Endian
format you have contains the marker bytes I mentioned. If it does, I'm not
sure the first of the above will help, and possibly not the second. If it
does not, it might be interesting to try saving manually as Little Endian
(in which case I'm fairly sure Word will add the marker) and see if that
file works. But if you can't actually get your application to generate that
format, it's really of academic interest only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top