none
How to open a word document in Document Level Project? RRS feed

  • Question

  • Hi,

    I am trying to open a word document saved on the hard drive from a document-level project. <g class="gr_ gr_262 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="262" id="262">It looks</g> like I can not open any document using code at runtime other than manage the created word file at the time design? Is my assumption correct? or I am doing something wrong?

    Basically, my project needs me to retrieve the file from the database and open it from dot net application and let the user manipulate this word document using the application directly (not form Word application) and when the user saves the document it gets saved back to the database.

    Hence I thought document level VSTO is the right tool. But currently, I am not able to open any existing to documents and add them to the collection

    I tried the following code 

     Private Sub ThisDocument_Startup() Handles Me.Startup

            Dim d As Microsoft.Office.Tools.Word.Document = ThisApplication.Documents.Open(FileName:="C:\TestFile.docx", ReadOnly:=True)
            Me.ThisApplication.Documents.Add(d) ' I am getting type mismatch error here
    End Sub

    Basically, I am getting type mismatch error, probably its because COM object is mapped to the managed object.

    Please suggest what is the right way of achieving my requirement?


    RK

    Saturday, April 6, 2019 8:48 AM