Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / August 2007

Tip: Looking for answers? Try searching our database.

Automating Mailmerge using CSV results in squares / Japanese characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Guabble - 15 Aug 2007 17:26 GMT
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
Peter Jamieson - 15 Aug 2007 18:07 GMT
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/microsoft.public.word.mailmerge.fields/browse_thr
ead/thread/dc1076d59b977c64/d39588c43fc31d70?lnk=st&q=jamieson+SCHEMA.INI+odc+te
xt+unicode&rnum=1


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

Peter Jamieson

> 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
[quoted text clipped - 37 lines]
>            aLocalDoc.MailMerge.Execute()
> end if
Guabble - 16 Aug 2007 14:17 GMT
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()
Guabble - 16 Aug 2007 15:11 GMT
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)

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.