另存为编辑的Word文档VB.NET

时间:2015-02-03 09:55:06

标签: vb.net ms-word ms-office

我在尝试将修改后的Word文档保存为pdf或doc时出错:

  

MütabakatKontrol发生了未处理的“System.Runtime.InteropServices.COMException”类型异常。

objWordApp = New Word.Application

Dim objDoc As Word.Document

objWordApp.Documents.Open(dosyaword)
objDoc = objWordApp.ActiveDocument

objDoc.Content.Find.Execute(FindText:="&%/FIRMA_ADI\%&", _
  ReplaceWith:=ListBox9.Items(0).ToString, _
  Replace:=Word.WdReplace.wdReplaceAll)
objDoc.Content.Find.Execute(FindText:="&%/BAKIYE\%&", _
  ReplaceWith:=ListBox12.Items(0).ToString & parabirimi, _
  Replace:=Word.WdReplace.wdReplaceAll)
objDoc.Content.Find.Execute(FindText:="&%/TARIH\%&", _
  ReplaceWith:=ListBox13.Items(0).ToString, _
  Replace:=Word.WdReplace.wdReplaceAll)
While objDoc.Content.Find.Execute(FindText:="  ", _
    Wrap:=Word.WdFindWrap.wdFindContinue)
    objDoc.Content.Find.Execute(FindText:="  ", ReplaceWith:=" ", _
        Replace:=Word.WdReplace.wdReplaceAll, _
        Wrap:=Word.WdFindWrap.wdFindContinue)
End While

objWordApp.Documents.Item(1).SaveAsQuickStyleSet(Application.StartupPath
  & "\PDF\" & ListBox8.Items(0).ToString & ".doc")

objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
objWordApp.Quit()
objWordApp = Nothing

0 个答案:

没有答案