VB.net 中有没有一种方法可以将 Word 文档另存为不同的格式(即 Me.Application.ActiveDocument.SaveAs)而无需切换到它?例如,如果当前文档是未保存的,我想将该文档的副本另存为 HTML,但仍保持未保存的文档处于活动状态。
问问题
10817 次
1 回答
2
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
于 2012-05-18T09:02:34.027 回答