Automating Mailmerge using CSV results in squares / Japanese characters

G

Guabble

Im using ASp.net to automate a mail merge using a CSV file and a word
doc however the resulting file is just garbage. none of the merge
fields are filled in, and the pages are made up of lots of small
squares due to I would imagine encoding problems, as there are a
couple of Japanese Yen symbols in there too.

How do I get encode the resultant file or get it to work properly).
Using ASP.net 2, Word 2003 and Excel to create the CSV file.

many thanks
Mike

My Code is this

Dim aLocalWdApp As Word.Application
Dim aLocalDoc As Word.Document
Dim strConnect As String
Dim strFilePath As String
strFilePath =
HttpContext.Current.Server.MapPath(db.m_Global_Document_Path)
PrintMergeDocuments = False
aLocalWdApp = New Word.Application


aLocalWdApp.ChangeFileOpenDirectory(strFilePath)

aLocalDoc = aLocalWdApp.Documents.Open(FileName:=strFilePath &
strTemplateName, Format:=4, Encoding:=65001)


aLocalWdApp.Visible = True
aLocalWdApp.ActiveDocument.MailMerge.MainDocumentType = 0
'WdMailMergeMainDocType.wdFormLetters

aLocalDoc.MailMerge.OpenDataSource(strFilePath &
ConstantsClass.cCSVHEADINGS_FILENAME, , , True, , False)

aLocalDoc.MailMerge.Destination = 0 ' wdSendToNewDocument

If aLocalDoc.MailMerge.State = 2 Then ' wdMainAndDataSource
Then
aLocalDoc.MailMerge.Execute()
end if
 
P

Peter Jamieson

It is probably worth seeing if setting the DefaultCPG registry value
described in

http://support.microsoft.com/kb/290981/en-us

(It's also possible that opening the document in Word with an explicit
encoding , saving it as a Word document, then using that as the data source
for a merge, as described in that article, might do the trick).

If your data source has 255 columns or fewer, and you are using Word 2003,
you can try the approach using .odc and SCHEMA.INI that I described in the
conversation beginning at

http://groups.google.com/group/micr...q=jamieson+SCHEMA.INI+odc+text+unicode&rnum=1

I would be interested to know whether either of these things fixes it for
you.

Peter Jamieson
 
G

Guabble

I have noticed that when you actually open the document, its encoding
(i think) is wrong. I have tried the UK (20285), Auto Detect (50001),
UTF-8 ( 65001), MSOENCODINGUSASCII (20127) & MSOENCODINGWESTERN (1252)
and many more . It works if I click on it in Explorer. I am running
the code locally so I dont think it would be a server setting). What
could be doing this?

Dim aLocalWdApp As Word.Application

Dim aLocalDoc As Word.Document

Dim strFilePath As String

strFilePath =
HttpContext.Current.Server.MapPath(db.m_Global_Document_Path)

Dim strTemplateName As String = "Reminder1Letters.dot"

aLocalWdApp = New Word.Application

aLocalWdApp.ChangeFileOpenDirectory(strFilePath)

aLocalDoc = aLocalWdApp.Documents.Open(FileName:=strFilePath &
strTemplateName, Format:=4, Encoding:=20285)

aLocalWdApp.Visible = True ' PUT A BREAK HERE

aLocalDoc.Close()

aLocalWdApp.Quit()
 
G

Guabble

now fixed!

It was the line

aLocalDoc = aLocalWdApp.Documents.Open(FileName:=strFilePath &
strTemplateName, Format:=4, Encoding:=20285)

i took out the last 2 arguments and its fine, the encoding, and the
Word document type, ie

aLocalDoc = aLocalWdApp.Documents.Open(FileName:=strFilePath &
strTemplateName)
 

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