none
Problem with ActiveDocument.MailMerge.OpenDataSource(), read only words documents & Office 2013 [C++]

    Question

  • Hi, 

    I have a problem with a C++ developpement & Office 2013.

    The C++ program open a .doc source document (named for example "_TEST.doc", with fields name & value semicolon separated) and a model document (named "TEST.doc") and merge it in a new document.

    I encountered an issue (with office 2013) when "TEST.doc" was in read only mode (but not when in normal mode) : the program begin to open the model ("TEST.doc") then the source doc ("_TEST.doc") but failed at this task (wich is quite strange, nothing should change beetween these 2 type of execution since "_TEST.doc" seem to be the same, it's only "TEST.doc" read only attribute wich change).

    After some debugging I came to be aware that if I began to open "_TEST.doc" then "TEST.doc" in my C++ program, the program fail in all case ("TEST.doc" read/write or read only).

    All in all it's this portion of code wich fail (trying to open a word "_TEST.doc") : 

    String ^ strPathSourceModele = "somepath";

    Application ^wrdApp = gcnew Application();

    wrdApp->ActiveDocument->MailMerge->OpenDataSource(strPathSourceModele, oMissing,
    oMissing, oMissing, oMissing, oMissing,
    oMissing, oMissing, oMissing, oMissing,
    oMissing, oMissing, oMissing, oMissing,
    oMissing, oMissing);

    Any light on the issue ? Compatibility problem ? The bug seem to happen only with office 2013, and versions of Visual C++ don't seem to change anything.

    Thx

    Wednesday, April 9, 2014 3:11 PM

All replies

  • Can't edit, sry, but : 

    Of course what fail in the code is 

    wrdApp->ActiveDocument->MailMerge->OpenDataSource(...)

    not previous instructions...



    • Edited by no_id Wednesday, April 9, 2014 3:16 PM
    Wednesday, April 9, 2014 3:16 PM
  • Hello,

    Did you try to specify the ReadOnly parameter passing the true value for the OpenDataSource Me method?

    Pass true to open the data source on a read-only basis.

    Wednesday, April 9, 2014 3:41 PM
  • Thx for your response.

    Yes I tried as I was thinking it was only a read only issue, but it seem to be more complex : the method wich fail try to open the document in normal mode (not read only) either ways ("_TEST.doc" is always in normal mode in my program, it's only "TEST.doc" wich change).

    Globally when the code begin to open TEST.doc then _TEST.doc, it fail at openning _TEST.doc if TEST.doc is read only, and it succeed at openning _TEST.doc if TEST.doc is normal mode.

    The previous case suggest it's a read only problem but imo it's not the crux of the issue since if the code begin to open _TEST.doc then TEST.doc it always fail.

    I think the problem is more about the method OpenDataSource itself & some sort of Compatibility problem.

    The thing is I can't easily test with .docx documents because the generation of .doc document depend on another program.
    • Edited by no_id Wednesday, April 9, 2014 4:39 PM
    Wednesday, April 9, 2014 4:35 PM
  • Did you install Service Pack 1 for Office 2013?

    > The thing is I can't easily test with .docx documents because the generation of .doc document depend on another program.

    Did you have a chance to test .docx files? Do they work as expected?

    Wednesday, April 9, 2014 5:31 PM
  • Ok it seem I've done a big step for the resolution of the issue : 

    Ive tried executing the following code in C# : 



    String strSource = "D:\\rep_test_doc\\_CRFIN.doc";
    wrdApp.ActiveDocument.MailMerge.OpenDataSource(strSource, Type.Missing, false);



    It fail because the program want the model to be opened before the source. So I came to the point it was not wrdApp->ActiveDocument->MailMerge->OpenDataSource wich was failing but the opening of read-only model (wrdDoc = wrdApp->Documents->Open) (simple rationnal : the program fail at openning the source because the model didn't open properly due to some reason).

    So the code became : 

    //model

    String strModel = "D:\\rep_test_doc\\TEST.doc";
    Document wrdDoc = wrdApp.Documents.Open(strModel, Type.Missing, true);

    //source            
    String strSource = "D:\\rep_test_doc\\_TEST.doc";
    wrdApp.ActiveDocument.MailMerge.OpenDataSource(strSource, Type.Missing, false);





    wich failed exactly as our c++ program fail (at wrdApp.ActiveDocument.MailMerge.OpenDataSource) but with a better error message.

     Changing the parameter of opening method to read-only = true didn't solve the problem, but adding "wrdDoc.ActiveWindow.View.Type = WdViewType.wdNormalView;" after "Document wrdDoc = wrdApp.Documents.Open(strModel, Type.Missing, true);" made the program executing without exception.

    The only problem lefting is that translating c# "wrdDoc.ActiveWindow.View.Type = WdViewType.wdNormalView;" to c++/CLI "wrdDoc->ActiveWindow->View->Type = WdViewType::wdNormalView;" throw a weird compilation error, but it's outside the scope of this post.



    Anyway I bet the original question of the post is 90% solved : one need to add "wrdDoc.ActiveWindow.View.Type = WdViewType.wdNormalView" after opening a read-only doc with Office 2013 when using interop dll/libraries.  














    • Edited by no_id Thursday, April 10, 2014 1:40 PM
    Thursday, April 10, 2014 1:34 PM
  • Hi no_id

    If you're upgrading from Word 2007 or earlier then the problem may be that the main merge document is opening in reading mode (http://blogs.msmvps.com/wordmeister/2013/02/22/word2013bug-not-available-for-reading/) or a protected window ("sandboxed"). That can cause lots of automation code to fail that worked in previous versions.

    http://office.microsoft.com/en-001/word-help/what-is-protected-view-HA010355931.aspx

    http://msdn.microsoft.com/en-us/library/hh128817(v=office.14).aspx


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, April 12, 2014 3:33 PM
    Moderator