How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Steve Herrod Your Own Question

Steve Herrod
Steve Herrod, Computer Support Specialist
Category: Microsoft Office
Satisfied Customers: 2729
Experience:  Trained in Microsoft Office from 2000 through to latest version 2010.
65126503
Type Your Microsoft Office Question Here...
Steve Herrod is online now
A new question is answered every 9 seconds

Using VB macro in Word 2007 to do a mail merge. Data source

Resolved Question:

Using VB macro in Word 2007 to do a mail merge. Data source is a text file (.txt). When the macro runs it assumes the text file is using Shift-JIS (Japanese) encoding and any accented characters (e.g. é) are combined with the following character and converted to a Japanese character. Have tried using: .OpenDataSource Format:=wdOpenFormatText, ConfirmConversions:=False and variants to no avail.


 


When I do the mail merge manually it also defaults to Shift-JIS, but it gives me the "File Conversion" dialog box in which I can change to "Windows (Default)" encoding. That solves the problem, but I need the macro to run without user intervention.


 


I can send files if you want...

Submitted: 2 years ago.
Category: Microsoft Office
Expert:  Steve Herrod replied 2 years ago.

Steve Herrod :

Hi, I'll be happy to help with this issue


 

Steve Herrod :

would it be possible to get a copy of the text file to do some testing here with?


 

Steve Herrod :

There are a few issues surrounding this type of operation but with the source file it should be possible to get a macro workaround so that user intervention isn't required.


 

Steve Herrod :

 


 

Steve Herrod :

Cheers


 

Steve Herrod :

Steve


 

Customer:

I have files, but how do I upload them?

Steve Herrod : Hi
Steve Herrod : If you go to wikisend.com and choose upload
Steve Herrod : then you can add the files and let me know the download links it gives you
Customer:

OK. The links are below. Test.doc is the mail merge form (catalog type) and contains the macro. Test.txt is the data file.



http://wikisend.com/download/349156/test.doc


http://wikisend.com/download/232060/test.txt

Steve Herrod :

thanks

Customer:

Hello,



Here is some clarification.



Open test.doc and run the macro "test". It should perform the merge and then close test.doc, leaving the new catalog open. When I do this the LastName in the second record is "For" followed by a Japanese character. As you can see from test.txt, the correct data is "Forêt". The fourth character is Windows ANSI code 234. Word has assumed that the text file is encoded as "Japanese (Shift-JIS)".



More to come...



Steve Herrod :

thanks....

Customer:

...



Note that test.doc is saved as a "normal Word document". This is done so user intervention is not required during macro execution. If test.doc is saved as a mail merge form, then Word prompts to execute the query when test.doc is opened. So, when you try to do the merge manually (see below) and then close test.doc, Word will prompt to save changes. Don't!



Try the merge manually from test.doc. To do this you must first associate the data file ("recipient list" in Word 2007). When I do this I get the "file conversion" dialog. The "other encoding" radio button is selected and "Japanese (Shift-JIS)" is highlighted in the selection box. The preview pane shows the Japanese character. If I change the encoding to, for example, Western European (Windows),Western European (ISO) or Unicode (UTF-7), the data appears correctly in the preview pane.



So to summarize, I am looking for a change in the macro or Word or Windows configuration parameters that will prevent Word from assuming that the encoding is Shift-JIS.



More to come...

Customer:

...



Also, when doing the merge manually, the Windows (default) radio button has the desired result.



The issue only occurs when the data file contains "foreign" characters, i.e. those between code 128 and 255. If there aren't any of these characters in the data file, the macro works perfectly and the "file conversion" dialog does not appear when the merge is attempted manually.



Any questions?


Steve Herrod :

sorry - only just got the messages through

Steve Herrod :

that shoudl be ok, will work on that now and come back to you asap

Steve Herrod :

Trying various ways of inserting an encoding format but no joy so far

Steve Herrod :

still trying though

Customer:

Any luck?

Steve Herrod :

Not so far - trying to force the encoding into the macro doesn't seem to work correctly, whatever method is used

Steve Herrod :

I don't want to give up just yet though...

Customer:

I see that my question is now closed. Does this mean you have given up?

Customer:

Hi Steve,


 


I just telephoned JustAnswer and they re-opened the question. What's up?

Steve Herrod :

Apologies - not sure why it was closed, am still working on this

Steve Herrod :

will send an update later today as planning to crack this in the afternoon

Customer:

Apparently, it closes after a certain amount of time...

Steve Herrod :

ah ok - always thought that was a week without any updates...

Steve Herrod :

nevermind though, will get to it

Steve Herrod :

Haven't found a conclusive way of resolving this

Steve Herrod :

But if you create and run this macro

Steve Herrod :

Set docText = Documents.Open(FileName:="\\Server\data\Test.txt", _
Format:=wdOpenFormatText, _
Encoding:=msoEncodingISO88591Latin1, _
Visible:=False, _
NoEncodingDialog:=True)

Steve Herrod :

and then run your macro the character appears fine

Steve Herrod :

for some reason I cannot get the macro in your file to accept the Encoding:=msoEncodingISO88591Latin1, _ line

Customer:

I have added this to the beginning of the macro in test.doc:


 

Customer:

I have added this


 

Customer:

I have added this to the beginning of the macro "test" in test.doc:


'set up encoding'
Dim docText As Variant
Set docText = Documents.Open(FileName:="test.txt", _
ReadOnly:=True, Format:=wdOpenFormatText, _
Encoding:=msoEncodingISO88591Latin1, _
Visible:=False, _
NoEncodingDialog:=True)


and now the mailmerge works properly. Why? What does your SET macro do?


 

Customer:

Note that I had to add the ReadOnly parameter...

Steve Herrod :

I think the SET macro just allows a specific encoding variable to be added


 

Customer:

I need to leave the office now, returning Tuesday AM. I'll test this in a real environment and then we can close the question. Thanks for your help.

Steve Herrod :

no problem


 

Steve Herrod :

Let me know whenever is convenient


 

Steve Herrod :

Cheers


 

Steve Herrod :

Steve


 

Customer:

Hi Steve,


 

Customer:

msoEncodingWestern works just as well.

Adding the following to my macros makes them work unattended and without any Japanese characters appearing:


 

Steve Herrod :

ok - sounds good


 

Customer:

Dim x As Variant
Set x = Documents.Open _
(FileName:="OpenDataSourceNameParameter", _
Visible:=False, Encoding:=msoEncodingWestern)

I think the root solution lies in the "system code page", whatever that is.



 

Customer:

In any event, job well done. Thanks.

Steve Herrod :

yes - that makes sense


 

Steve Herrod :

glad you have something which is working


 

Steve Herrod, Computer Support Specialist
Category: Microsoft Office
Satisfied Customers: 2729
Experience: Trained in Microsoft Office from 2000 through to latest version 2010.
Steve Herrod and 2 other Microsoft Office Specialists are ready to help you

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
< Last | Next >
  • http://ww2.justanswer.com/uploads/JS/jstinehelfer/2012-6-6_215146_Pictureofme1.64x64.png jstinehelfer's Avatar

    jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
  • http://ww2.justanswer.com/uploads/JA/JasonJames122/2011-12-16_135647_jasonjamesheadshotweb.64x64.jpg JasonJames122's Avatar

    JasonJames122

    Computer Enthusiast

    Satisfied Customers:

    0
    I manage all information systems (network of Windows PC's and servers with Microsoft Office products) for a small business
  • http://ww2.justanswer.com/uploads/JE/jessmagz/2012-6-6_18129_jm.64x64.jpg Jess M.'s Avatar

    Jess M.

    Computer Support Specialist

    Satisfied Customers:

    301
    Computer Software Specialist for more than 10 years
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Computer Manager

    Satisfied Customers:

    274
    20 years experience providing remote computer support
  • http://ww2.justanswer.com/uploads/SP/spherrod/2012-6-6_174244_1000852.64x64.JPG Steve Herrod's Avatar

    Steve Herrod

    Computer Support Specialist

    Satisfied Customers:

    125
    Trained in Microsoft Office from 2000 through to latest version 2010.
  • http://ww2.justanswer.com/uploads/SE/Seashore2011/2011-12-6_33418_111205223015.64x64.jpg Chris L.'s Avatar

    Chris L.

    Support Specialist

    Satisfied Customers:

    124
    Certified Expert with over 10 years experience.
  • http://ww2.justanswer.com/uploads/KR/krkljatorm/2012-6-24_153417_ITMiro.64x64.jpg IT Miro's Avatar

    IT Miro

    Computer Scientist

    Satisfied Customers:

    97
    Bachelor's Degree in Information Technology, Microsoft Certified Professional
 
 
 
Chat Now With A Microsoft Office Technician
Steve Herrod
Steve Herrod
Staff Systems Analyst
132 Satisfied Customers
Trained in Microsoft Office from 2000 through to latest version 2010.