Save Word document in a different format without an effective active document

Is there a way in VB.net to save a Word document in a different format (i.e. Me.Application.ActiveDocument.SaveAs) without switching to it? For example, if the current document is unsaved, I want to save a copy of this document as HTML, but still save the unsaved document.

+3
source share
1 answer

Copy the current doc variable to another variable and save it.

 Try
        Dim oWord As Word.Application
        Dim oDoc As Word.Document



        'Start Word and open the document template.
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add
        oDoc.PageSetup.TopMargin = oWord.CentimetersToPoints(5.08)
        oDoc.PageSetup.LeftMargin = oWord.CentimetersToPoints(4.57)
            oDoc.PageSetup.RightMargin = oWord.CentimetersToPoints(1.27)
            oDoc.PageSetup.BottomMargin = oWord.CentimetersToPoints(3.81)
            oDoc.PageSetup.PageHeight = oWord.CentimetersToPoints(29.7)
            oDoc.PageSetup.PageWidth = oWord.CentimetersToPoints(21)

            'TIll Above your entire odoc is formatted
            'From below I will save it to my own code

            Dim newdoc As Word.Document
            newdoc = oDoc
            newdoc.SaveAs2("d:\file.pdf", Word.WdSaveFormat.wdFormatPDF)

            'All done. Close this form.
            'BSPGlobals.DataBase.Contact.ExitApp()
            MessageBox.Show("Print to Doc Done.")
        Catch ex As Exception
            MessageBox.Show("Error at Printing the bill." & vbCrLf & ex.Message)
        End Try
+2
source

All Articles