在VB.net中是否有办法将Word文档另存为不同格式(即Me.Application.ActiveDocument.SaveAs)而无需切换到它?例如,如果当前文档是未保存的,我想将该文档的副本保存为HTML,但仍保持未保存的文档处于活动状态。
答案 0 :(得分:2)
将当前doc变量复制到另一个变量并保存。
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