none
Mail merge in Word 2013 RRS feed

  • Question

  • Hi, all.

    We used simple script to automate mail merge with Word:

    WshShell = WScript.CreateObject("WScript.Shell");
    fso = WScript.CreateObject("Scripting.FileSystemObject");
    rootPath = fso.GetParentFolderName(WScript.ScriptFullName);

    var templDoc, oWord, outDoc, i;

    oWord = WScript.CreateObject("Word.Application");
    templDoc = oWord.Documents.Open(fso.BuildPath(rootPath, "a.doc"),false,true);

    dataSrcName = fso.BuildPath(rootPath, "datasrc.docx");

    with(templDoc.MailMerge) {
      OpenDataSource(dataSrcName);
      Destination = 0;  SuppressBlankLines = true;  Execute(true);
    }
    oWord.Quit(false); oWord = null;

    WScript.echo("Finished");

    It worked good with all versions until version 2013.

    With 2013 it says "Method OpenDataSource is not available for reading.".

    But when i call it internally from macro inside Word, the same code works.

     

    So, 1) Have anybody reach similar problém?

    2)  Can somebody help me with making the mailmerge functional ?

    (e.g. call mailmerge from script using already prepared document and adress source file)

     

    thanks for any recommendation

    Jiri Kaspar, Prague


    Jiri Kaspar, ICZ

    Friday, October 18, 2013 11:53 AM

Answers

  • Hi Jiri

    First thing to do when trouble-shooting this kind of thing is to make sure you can see what state Word is in, so

        oword.Visible = true;

    Then, from the error message I'm guessing that Word may be opening the document in a "protected" state, so the OpenDataSource command isn't available. This may have something to do with the origin of the document (network or internet origin, for example). So take a look whether there's a message bar across the top of the document warning the user?

    Note, please, that the recommended way to generate documents these days is to create them via the Office Open XML file format. This would include "merging" data into a document to create a single document or a series of documents. For this, the Word Application is not required, so you won't run into Word's security checks, execution will be faster and you'll be better off in a server environment, where automation is no supported. You can find more on the topic at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, October 19, 2013 6:56 PM
    Moderator

All replies

  • Hi Jiri

    First thing to do when trouble-shooting this kind of thing is to make sure you can see what state Word is in, so

        oword.Visible = true;

    Then, from the error message I'm guessing that Word may be opening the document in a "protected" state, so the OpenDataSource command isn't available. This may have something to do with the origin of the document (network or internet origin, for example). So take a look whether there's a message bar across the top of the document warning the user?

    Note, please, that the recommended way to generate documents these days is to create them via the Office Open XML file format. This would include "merging" data into a document to create a single document or a series of documents. For this, the Word Application is not required, so you won't run into Word's security checks, execution will be faster and you'll be better off in a server environment, where automation is no supported. You can find more on the topic at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, October 19, 2013 6:56 PM
    Moderator
  • Hi, 

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question.

    Thanks for your understanding. 
    Best regards, 
    Luna


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 24, 2013 12:21 PM
    Moderator