none
Issue with OLE object of MS Word 2016. It is not saving the document and giving error. RRS feed

  • Question

  • We are creating OLE object of MS Word using following code: 

    Type objClassType = Type.GetTypeFromProgID("Word.Basic");
    object obj =  Activator.CreateInstance(objClassType);        
    return obj;

    Now when we try to use FileSaveAs() command for the above object it gives error "The FileSaveAs is not available because a document window is not active."

    Document window is open and active. It is working fine with office 2013. This is only happening with office 2016. 

    Any help is deeply appreciated.

    Regards



    Thursday, December 8, 2016 9:54 AM

Answers

  • In addition to above above details, the word document that we are trying to save is opened by a third party software (HotDocs) using their API. As I mentioned earlier this entire flow is working fine till Office 2013. It is only giving issue with Office 2016.

    Regards,

    Saleem Mewati

    • Marked as answer by Saleem Mewati Friday, January 13, 2017 9:11 AM
    Monday, December 19, 2016 12:32 PM
  • I have made changes in code to make Word object using "Word.Application" in place of "Word.Basic". This works.
    • Marked as answer by Saleem Mewati Friday, January 13, 2017 9:13 AM
    Friday, January 13, 2017 9:13 AM

All replies

  • Your question needs to be moved to the Word for Developers forum, since this is not a C# issue:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, December 8, 2016 2:34 PM
  • Hi Saleem Mewati,

    Thank you for posting here.

    According to your question is more related to Word, I will move it to Word for Developers for suitable support.

    The Visual C# Form discuss and ask the question about the C# programming language, IDE, libraries, samples and tools.

    If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 9, 2016 1:58 AM
  • Thanks for doing that for me.
    Friday, December 9, 2016 4:55 AM
  • Hi,

    How do you use FileSaveAs() command?

    I could successfully use code below both in Office2013 and 2016 to open and then save files.

                Type objClassType = Type.GetTypeFromProgID("Word.Basic");
                object obj = Activator.CreateInstance(objClassType);
                objClassType.InvokeMember("FileOpen", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[1] { @"C:\Demo.docx" });
                objClassType.InvokeMember("FileSaveAs", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[1] { @"C:\Demo1.docx" });

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 12, 2016 8:24 AM
    Moderator
  • For the above given object I am using following way:

    obj.FileSaveAs(Name:=s)


    s is name of file including path. This entire code of handling Word operations is written in VB.Net. Before postinh this I have tried InvokeMember too but no luck.

    Regards,
    Saleem Mewati

    Monday, December 12, 2016 1:46 PM
  • Hi,

    Do you check if the opened Word windows and the instance created by code are the same one?

    I could reproduce the exception when there is no document opened or one document is opened manually.

    I think you get the exception because they are not in the same instance.

    How do you open the document? I suggest you open it in the same instance. Or you could use  GetObject Function (Visual Basic) to get current instance.

    E.g.

            Dim objClassType As Type = Type.GetTypeFromProgID("Word.Basic")

            Dim obj As Object = Activator.CreateInstance(objClassType)

            'objClassType.InvokeMember("FileOpen", BindingFlags.[Default] Or BindingFlags.InvokeMethod, Nothing, obj, New Object(0) {"C:\Demo.docx"})

            'objClassType.InvokeMember("FileSaveAs", BindingFlags.[Default] Or BindingFlags.InvokeMethod, Nothing, obj, New Object(0) {"C:\Demo11.docx"})

            obj.FileOpen("C:\Demo.docx")

            obj.FileSaveAs(Name:="C:\Demo1.docx")

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 13, 2016 9:43 AM
    Moderator
  • Hi,

    It is the same instance but a newly created document, not an existing one that I am trying to save. I will update this with more details.

    Regards.
    Saleem Mewati

    Tuesday, December 13, 2016 10:29 AM
  • Hello Saleem,

    Do you try to automate Word or VBA editor?

    The Word object model doesn't provide any FileSaveAs methods. You can see only the SaveAs2 method of the Document class.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, December 13, 2016 1:31 PM
  • I am checking my code thoroughly and will update here if found anything. So far no luck.

    Regards,

    Saleem Mewati

     
    Monday, December 19, 2016 4:59 AM
  • In addition to above above details, the word document that we are trying to save is opened by a third party software (HotDocs) using their API. As I mentioned earlier this entire flow is working fine till Office 2013. It is only giving issue with Office 2016.

    Regards,

    Saleem Mewati

    • Marked as answer by Saleem Mewati Friday, January 13, 2017 9:11 AM
    Monday, December 19, 2016 12:32 PM
  • I have made changes in code to make Word object using "Word.Application" in place of "Word.Basic". This works.
    • Marked as answer by Saleem Mewati Friday, January 13, 2017 9:13 AM
    Friday, January 13, 2017 9:13 AM