Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Thierry Thoua Thierry Thoua is offline
external usenet poster
 
Posts: 1
Default Problems with mail merge (encoding)

Hello,

I've a "little" problem with Word interop (Office 11). I'd like to
automate the mailmerge.... I've a word file and a .txt file (a csv).
The text file is in UTF-8 encoding.

This is my "code" :

this.document.MailMerge.MainDocumentType =
WdMailMergeMainDocType.wdFormLetters;
this.document.MailMerge.Destination =
WdMailMergeDestination.wdSendToNewDocument;
object subType = WdMergeSubType.wdMergeSubTypeOther;
object format = WdOpenFormat.wdOpenFormatUnicodeText;
object confirmConversions = false;
this.document.MailMerge.OpenDataSource(cheminFichi er, ref
format, ref confirmConversions, ref ComWrapper.OpenDocumentAsReadOnly,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref subType);

document.MailMerge.Execute(ref ComWrapper.Missing);
object index = 1;
_Document mailMergeResult = this.word.Documents.get_Item
(ref index);

It works fine ... BUT .. Sometimes when I load a lot my service ...
The word doesn't use the "utf-8" encoding ... Word use "Windows
standard (default)" = When I execute the mail merge ... I've a window
with a wrong key "ïMyKey" and not "MyKey" .... What's wrong ???

Do you have any idea ?

Thanks
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Problems with mail merge (encoding)

!. As far as I know, word takes little or notice of the format parameter
when opening Mail Merge Data Sources. Some other parameters that have an
effect when opening a Document via, e.g. Documents.Open are also ignored
in OpenDataSource. Mailmerge tends to use other methods to try to work
out what kind of file it is dealing with.

2. What is probably happening is that
a. The method Word is using to open the text file is deciding the
encoding is not UTF-8. That might, for example, be because there is a
DefaultCPG setting in the registry (have a look under
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\W ord\Options
). There could well be other reasons why the text converter is not
recognising UTF-8 correctly, but I do not know what they might be,.
b. If the UTF-8 file does not have a BOM (Byte Order Mark) at the
beginning, then the name of the first column may be correct
c. if the UTF-8 file has a BOM, then Word will treat the BOM as the
first few characters of th efirst column name (in whatever encoding it
is expecting)

That assumes that Word is opening the file using its text converter,
which is what I /think/ your code will do (it's as if you were doing

OpenDataSource name:="the text file.txt"

) and if you are seeing the encoding dialog box that is almost certainly
what it is doing.

3. See if that leads anywhere first. Otherwise, it may be possible to
force Word to use UTF-8 encoding, but only if the OLE DB text provider
can read your files (maybe not if they have multiline texts or more than
255/256 columns), and you are in a position to create/maintain a couple
of other files.

Peter Jamieson

http://tips.pjmsn.me.uk

Thierry Thoua wrote:
Hello,

I've a "little" problem with Word interop (Office 11). I'd like to
automate the mailmerge.... I've a word file and a .txt file (a csv).
The text file is in UTF-8 encoding.

This is my "code" :

this.document.MailMerge.MainDocumentType =
WdMailMergeMainDocType.wdFormLetters;
this.document.MailMerge.Destination =
WdMailMergeDestination.wdSendToNewDocument;
object subType = WdMergeSubType.wdMergeSubTypeOther;
object format = WdOpenFormat.wdOpenFormatUnicodeText;
object confirmConversions = false;
this.document.MailMerge.OpenDataSource(cheminFichi er, ref
format, ref confirmConversions, ref ComWrapper.OpenDocumentAsReadOnly,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref ComWrapper.Missing,
ref
ComWrapper.Missing, ref ComWrapper.Missing, ref ComWrapper.Missing,
ref subType);

document.MailMerge.Execute(ref ComWrapper.Missing);
object index = 1;
_Document mailMergeResult = this.word.Documents.get_Item
(ref index);

It works fine ... BUT .. Sometimes when I load a lot my service ...
The word doesn't use the "utf-8" encoding ... Word use "Windows
standard (default)" = When I execute the mail merge ... I've a window
with a wrong key "ïMyKey" and not "MyKey" .... What's wrong ???

Do you have any idea ?

Thanks

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge problems. CD Tom Microsoft Word Help 0 May 1st 08 11:53 PM
Mail merge problems Can only mail merge one field at a time. New Users 1 August 17th 07 10:14 PM
Mail Merge Problems Mike G New Users 3 June 13th 07 05:35 PM
encoding problems in Word 2002 Mir Microsoft Word Help 5 September 28th 06 04:53 PM
Mail merge e-mail character encoding Michael Lee Mailmerge 2 August 10th 06 10:44 AM


All times are GMT +1. The time now is 06:24 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"