Working with Word and VB.net automation to build one Word document comprised of several documents appended together.
So I do Word.Documents.Add(firstDocument), and then go to the end of the file and do Word.Selection.InsertFile(secondDocument) and it works as expected, except that if firstDocument is for example Verdana 10pt and secondDocument is Calibiri 11, it's inserting secondDocument using the font & style of firstDocument.
I couldn't find anything in the documentation for Selection.InsertFile that would have any impact over the formatting, so I believe it must be controlled another way. I also tried inserting a page break and a section break (with page break) before inserting the file, but found that it made no difference on the font.
Currently I have the app copying everything from secondDocument, closing secondDocument, opening firstDocument, move to end and then paste. This is problematic for many reasons, but it preserves the formatting.
Any ideas how I can keep the exact formatting of secondDocument when inserting into firstDocument? I need to get away from using Clipboard!
Thanks!
EDIT: Here's the code I've been testing trying to get the logic right:
Public Sub TestingWord()
Dim thisApp As New Word.Application
Dim SourceDoc As New Word.Document
Dim DestDoc As New Word.Document
Try
thisApp.Visible = False
DestDoc = thisApp.Documents.Add("X:\Isaac\First.docx")
thisApp.Selection.WholeStory()
thisApp.Selection.EndKey(Unit:=6)
thisApp.Selection.InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
thisApp.Selection.InsertFile("X:\Isaac\Second.docx")
thisApp.Selection.WholeStory()
thisApp.Selection.EndKey(Unit:=6)
thisApp.Selection.InsertBreak(Word.WdBreakType.wdSectionBreakNextPage)
thisApp.Selection.InsertFile("X:\Isaac\Third.docx")
DestDoc.SaveAs2("X:\Isaac\Yo.docx")
thisApp.Quit(SaveChanges:=Word.WdSaveOptions.wdSaveChanges)
releaseObject(DestDoc)
releaseObject(SourceDoc)
releaseObject(thisApp)
Catch ex As Exception
MsgBox("Error: " & ex.Message.ToString)
Finally
MsgBox("Success!")
End Try
End Sub