The application I support is creating an amalgamted Word document by copying couple of Word documents in one document right after each other.
The problem is the format of the some of the fields of the document that gets appended is changed in amalgamated document while the amalgamated document is the copy of AppendDocument
(imagine if we have one document to copy in the amalgamated document)
The first and second line of of the Word document looks like:
From: Mr x To: Gary Y
Address: NorkYork Date: 2010/05/01
From:, To:, Address: and Date: are bold and size 10 in the AppendDocument
while in amalgamated document they are bold but their size change to 12!
I confused I am not sure why the size for these 4 items are changed even their actual values have the same size!
Please see the below code which 2 documents path are passed. The first one is the BaseDocuemnt
or amalgamated document and the second one is the document which is appended.
Private Sub DocumentAppend(ByVal strBaseDocument As String, ByVal strAppendDocument As String)
Dim FirstDocument As Boolean
Dim fleBaseDocument As File
Dim wrdRange As Word.Range
Dim wrdAppendDocument As Word.DocumentClass
wrdAppendDocument = New Word.DocumentClass()
Dim AmalgamatedDocument As Word.DocumentClass
AmalgamatedDocument = New Word.DocumentClass()
Dim wrdApp As Word.ApplicationClass
wrdApp = AmalgamatedDocument.Application
Dim AmalgamatedDocumentRange As Word.Range
Try
wrdApp.Visible = True
If fleBaseDocument.Exists(strBaseDocument) Then
FirstDocument = False
AmalgamatedDocument = wrdApp.Documents.Open(strBaseDocument)
Else
FirstDocument = True
AmalgamatedDocument = wrdApp.Documents.Add()
End If
AmalgamatedDocumentRange = AmalgamatedDocument.Content
AmalgamatedDocumentRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
If Not FirstDocument Then
AmalgamatedDocumentRange.InsertBreak (Word.WdBreakType.wdSectionBreakNextPage)
End If
''# get the document to be appended
wrdAppendDocument = wrdApp.Documents.Open(strAppendDocument)
wrdAppendDocument.Activate()
wrdAppendDocument.Select()
''# +++++++++++++++++++++++
wrdApp.Selection.Copy()
wrdApp.Selection.CopyFormat()
AmalgamatedDocument.Activate()
wrdRange = AmalgamatedDocument.Content
wrdRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
wrdRange.Paste()
''# New
wrdApp.Selection.PasteFormat()
''# +++++++++++++++++++++++
wrdAppendDocument.Close()
''# save the new document
AmalgamatedDocument.SaveAs(FileName:=strBaseDocument)
AmalgamatedDocument.Close()
End Sub
Any advice would be greatly appreciated!