I am trying to make a word add-in that saves opened documents. I put a ribbon and button on it. Below is 开发者_高级运维the [button click handler] code I use for saving a word document in a specific location:
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 that document does not contain any content of the opened document; it just creates a new doc file.
What I am doing wrong? The event-handler on this button needs to behave the same as the event-handler on the standard Word save button, so how I can do this?
I can only imagine that maybe you need to create an object to represent the document itself first. Try the following:
Dim ThisApplication As Word.Application
Dim oDoc As Word.Document = ThisApplication.ActiveDocument
oDoc.SaveAs("C:\email")
oDoc.Close()
ThisApplication.Quit()
oDoc = Nothing
ThisApplication = Nothing
精彩评论