[Mail Merge] Prompt for Record and Field Delimiter breaking automation.

I have looked around the internet for the solution to the following problem and came across only a few similar threads, none of which have solved this issue for me.

  • I am using Mail Merge via Macros in my documents to automatically take data from a CSV file (letter.csv) and then call other macros to do processing. This automation was working perfectly for me in previous versions of MS Word.
  • In MS Word 2013 however, when the datasource .CSV file is opened via Mail Merge, I get a prompt from word to specify Field and Record delimiters. This not only breaks my automation, but no matter which delimiters I specify, the Mail Merge command always leads to an exception.

VB Code which causes the prompt and subsequent exception:

ActiveDocument.MailMerge.OpenDataSource Name:=ActiveDocument.Path & "\..\letter.csv", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _
        :=""

  • My data source is a simple .CSV file named 'letter.csv' with only 1 row and many fields in that row.
  • I have tried saving the .CSV as .txt and replacing the same in my macro. Also tried to seperate each field in the data source with a semi colon ; and identify each field with ""  eg. "field 1";"field 2"; None of it will cause word to take some kind of default delimiters and not give me this prompt.

Can someone suggest a workaround for this or maybe an alternative approach? My only restrictions are I can only use Visual Basic for my Macro code.

Thanks,

Shreeraj.

Answer
Answer

Try changing wdOpenFormatAuto to wdOpenFormatText.

 

An alternative, more circuitous option, would be to automate an Excel session, import the csv file into a workbook & save that as 'letter.xls', then use the saved Excel workbook as the datasource for the merge.

Cheers
Paul Edstein
(Fmr MS MVP - Word)

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 18, 2024 Views 3,577 Applies to: