여러 단어 문서를 하나의 문서로 병합하여 각 문서의 서식을 유지하는 프로그램을 작성 중입니다. 웹에 대한 몇 가지 연구는 다음과 같다 작동하도록되어 버전을 쓴 후 :VB NET에서 형식을 유지하는 단어 문서 병합
Public Sub processmodulestest(ByVal id As Integer)
Dim oMissing = System.Reflection.Missing.Value
Dim oFalse = False
Dim oTrue = True
Dim fileDirectory = "C:\<file-path>\MOD-TEST\"
Dim wrdApp As New Word.Application
Dim destDoc As Word.Document 'destination doc
Dim docfile As Word.Document 'tmp doc to paste
destDoc = wrdApp.Documents.Add
'docNew.PageSetup.TopMargin = wrdApp.InchesToPoints(1.0F)
'docNew.PageSetup.BottomMargin = wrdApp.InchesToPoints(0.0F)
Dim wordFiles() As String = Directory.GetFiles(fileDirectory, "*.doc")
wrdApp.Options.Pagination = False
wrdApp.ActiveWindow.View.ShowAll = True
For Each el As String In wordFiles
docfile = wrdApp.Documents.Open(el, False, False)
wrdApp.Selection.WholeStory()
wrdApp.Selection.Copy()
wrdApp.ActiveWindow.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
destDoc.Activate()
wrdApp.Selection.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting)
wrdApp.Selection.InsertBreak(Word.WdBreakType.wdPageBreak)
Next
wrdApp.Visible = True
End Sub
나는 다음과 같은 오류 얻을 :
An unhandled exception of type'System.Runtime.InteropServices.COMException'
HRESULT: 0x80010108 (RPC_E_DISCONNECTED)) The object invoked has disconnected from its clients.
다음 줄 참조 :
destDoc.Activate()
을
코드가 끝난 Office 인스턴스에서 정규화되지 않은 메서드를 사용하기 때문에 코드를 수정하는 방법을 이해할 수 없기 때문에이 내용을 읽어야합니다.
가이 코드를 보았다하지만 난 VB .NET으로 번역 할 수없는이기 때문에 어쩌면 그것의 그것을 – Slai