How to save an open document in vb.net format

I am trying to create an add-in for a word that preserves open documents. I put the ribbon and button on it. Below is the code [button click handler] that I use to save a text document in a specific place:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
        Dim ThisApplication As Word.Application
        ThisApplication.ActiveDocument.SaveAs("C:\email")
        ThisApplication.Quit()
        ThisApplication= Nothing
        End Sub

But when I click on this button, I create email.doc, but this document does not contain any contents of the open document; it just creates a new document file.

What am I doing wrong? The event handler on this button should behave the same as the event handler on the standard Word save button, so how can I do this?

+3
source share
1 answer

, , , . :

Dim ThisApplication As Word.Application
Dim oDoc As Word.Document = ThisApplication.ActiveDocument
oDoc.SaveAs("C:\email")
oDoc.Close()        
ThisApplication.Quit()
oDoc = Nothing
ThisApplication = Nothing
+2

Source: https://habr.com/ru/post/1741283/


All Articles