Vb.net 以其他格式保存Word文档而不保存有效的活动文档

Vb.net 以其他格式保存Word文档而不保存有效的活动文档,vb.net,Vb.net,在VB.net中,有没有一种方法可以将Word文档保存为不同的格式(即Me.Application.ActiveDocument.SaveAs),而不切换到其他格式?例如,如果当前文档是未保存的,我希望将该文档的副本保存为HTML,但仍保持未保存文档的活动状态。将当前文档变量复制到另一个变量并保存它 Try Dim oWord As Word.Application Dim oDoc As Word.Document 'Start Word

在VB.net中,有没有一种方法可以将Word文档保存为不同的格式(即Me.Application.ActiveDocument.SaveAs),而不切换到其他格式?例如,如果当前文档是未保存的,我希望将该文档的副本保存为HTML,但仍保持未保存文档的活动状态。

将当前文档变量复制到另一个变量并保存它

 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

谢谢,我会尝试一下。是否要保存一个不是ActiveDocument的文档?还是要在活动文档上使用“另存为”功能?我想在后台保存活动文档的副本,但不切换到保存的副本。saveAs的默认行为将打开保存的文档。