Mail merge-Japanese and English

S

sohpr

We are facing a very wierd issue. I have explained the issue below:

What we want to do:
- Send Japanese emails (with Japanese subject as well as fields) from an
English operating system and office.
- The emails should be in plain text

Software
-MS Office 2003 and Windows XP.
- Japanese IME is enabled (We can type Japanese in MS word, Excel, Outlook,
Date format in Outlook is also in Japanese, we can read/write Japanese emails)

What is the error:
When we do a mailmerge we get an encoding error if we want to send the email
in plain text. The emails work well in HTML format. But in plain text we get
a file conversion encoding error. The error reads like:
--------------------------
THE DOCUMENT MAY CONTAIN TEXT CONTENT WHICH WILL BE LOST UPON CONVERSION TO
THE CHOSEN ENCODING. TO PRESERVE THIS CONTENT FURTHER, CLICK NO TO EXIT THIS
DIALOG, THEN CHOOSE ANOTHER ENCODING THAT SUPPORTS THAT LANGUAGES IN THE
DOCUMENT. CONTINUE WITH SAVE?

FILE CONVERSION

WARNING: SAVING AS A TEXT FILE WILL CAUSE ALL FORMATTING, PICTURES, AND
OBJECTS IN YOUR FILE TO BE LOST.

TEXT ENCODING (THREE OPTIONS)
-WINDOWS DEFAULT(SELECTED)
-MS-DOS
-OTHER ENCODING(I CAN CHOOSE MY ENCODING)

FUTHER DOWN THERE ARE SOME OTHER OPTIONS OF LINE BREAKS ETC.

EVEN IF I CHOOSE A JAPANESE ENCODING (Shift_JIS or other japanese encoding)
THE ISSUE DOES NOT GET SOLVED.

--------------------------------------
The email comes with question marks "?". Even the subject has "?" marks.
mailmerge works well if I use English throughout the process.

How can I solve this problem?

Also, I want to attach files from a particular folder to the emails matching
the file names with a particular field. Example: A email with "6578" as a
field with fetch a file name "6578.pdf" from a predefined folder on the
PC/network. I am not sure if this is possible.

Looking forward to hearing from all of you.
 
P

Peter Jamieson

A rather late reply but I had to go and look around the various issues.

I may be wrong, but I don't think you will ever achieve what you want using
merge to plain text emails. There are various places in Word and Outlook
(and Windows) where encoding "rules" are specified, and it is quite
difficult to see what even one of those rules does, let alone which rules
might affect the overall outcome. At first i thought that by specifying the
right combination of rules, it might be possible to send a plain text with
an encoding specified by you. But I do not think it is, unless you can
change the Windows default encoding temporarily.
What is the error:
When we do a mailmerge we get an encoding error if we want to send the
email
in plain text. The emails work well in HTML format. But in plain text we
get
a file conversion encoding error. The error reads like:

At this point, what happens is that Word mailmerge wants to save a plain
text (encoded) version of your document, so that it can then insert that as
the body of the e-mail. However, on English-language Windows, it defaults to
trying to use "Windows (Default)", in this case "Western European (Windows)"
I do not think it is possible to change this default, even temporarily, but
you might want to ask in a more general Windows/Language/programming group.
It would probably be a lot more helpful if Word used one of the Unicode
encodings as the default.

If your text contains characters that cannot be encoded using the selected
encoding, the dialog box you have seen pops up, and you can select another
encoding. Perhaps you tried Japanese. I suspect that it might be better to
try one of the Unicode encodings.

At that point, Word saves the text file. It then has to insert the contents
in a plain text format mail message. I don't work for Microsoft and their
software is not open so I don't know how they do that, but it looks to me as
if they must be reading the encoded file in a way that does not work. Also,
even their "plain text" e-mails appear in fact to be HTML format messages
(look at the title bar of one that you read in Outlook).

I played around a bit, and although I have not tried to use a Japanese
encoding, the following macro seemed to do the trick for another East Asian
encoding. It saves each merged document as an encoded text file using the
Big-Endian Unicode encoding. Then, when the Outlook encoding is correctly
set up, Outlook seems to take the Unicode text and re-encode it correctly.
It is certainly worth a try, but if you cannot make it work then I suspect
that I will not be able to help further.

You will need to copy the macro text into a new module in the VBE editor,
then use Tools|Refereneces to make references to
Microsoft Outlook 11.0 Object Library
and
Microsoft Scripting Runtime.

I have just got to a point where this "works", so there may be other things
you can do to simplify. For example, it may not be necessary to save the
text at all as a file. But /a/ way is probably better than /no/ way, so here
you go.

Sub SendOneTextEncodedEmailPerSourceRec()
Dim bOutlookStarted As Boolean
Dim bTerminateMerge As Boolean
Dim intSourceRecord As Integer
Dim objMailItem As Outlook.MailItem
Dim objMerge As Word.MailMerge
Dim objOutlook As Outlook.Application
Dim strMailSubject As String
Dim strMailTo As String
Dim strMailBody As String
Dim strOutputDocumentName As String

bOutlookStarted = False
bTerminateMerge = False

' Set up a reference to the
' Activedocument, partly because
' the ActiveDocument changes as you
' merge each record

Set objMerge = ActiveDocument.MailMerge

' Start Outlook as necessary

On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlook = CreateObject("Outlook.Application")
bOutlookStarted = True
End If

With objMerge

' If no data source has been defined,
' do it here using OpenDataSource.
' But if it is already defined in the
' document, you should not need to
' define it here.

' .OpenDataSource _
' Name:="whatever"

intSourceRecord = 1

Do Until bTerminateMerge
.DataSource.ActiveRecord = intSourceRecord

' if we have gone past the end
' (and possibly, if there are no records)
' then the Activerecord will not be what
' we have just tried to set it to

If .DataSource.ActiveRecord <> intSourceRecord Then
bTerminateMerge = True
' the record exists
Else

' while we are looking at the
' correct activerecord,
' create the mail subject, body and "to"
' Just some sample code here - replace it with
' whatever you need

strMailSubject = _
"Results for " & _
objMerge.DataSource.DataFields("Firstname") & _
" " & objMerge.DataSource.DataFields("Lastname")

strMailTo = objMerge.DataSource.DataFields("Emailaddress")

' create the document path name
' In this case it can be te same for every recipient,
' but if you want to retain copies of the
' document, you can use info. in the data source

' this is an example - insert your
' own pathname here

strOutputDocumentName = "c:\a\results.txt"
.DataSource.FirstRecord = intSourceRecord
.DataSource.LastRecord = intSourceRecord
.Destination = wdSendToNewDocument
.Execute

' The Activedocument is always the
' output document

' Add any parameters you need to these calls
ActiveDocument.SaveAs _
FileName:=strOutputDocumentName, _
FileFormat:=wdFormatEncodedText, _
Encoding:=msoEncodingUnicodeBigEndian
ActiveDocument.Close

' Now create a

Set objMailItem = objOutlook.CreateItem(olMailItem)
With objMailItem
.Subject = strMailSubject
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs As Scripting.FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
Dim f As Scripting.TextStream
Set f = fs.OpenTextFile(strOutputDocumentName, ForReading, False,
TristateTrue)
.Body = f.ReadAll
f.Close
Set f = Nothing
Set fs = Nothing
.To = strMailTo
.Send
End With
Set objMailItem = Nothing

intSourceRecord = intSourceRecord + 1
End If
Loop
End With

' Close Outlook if appropriate

If bOutlookStarted Then
objOutlook.Quit
End If

Set objOutlook = Nothing
Set objMerge = Nothing

End Sub


Peter Jamieson
 

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