Add word document and keep formatting

2019-08-24 15:17发布

问题:

I am attempting to add my CV to the end of a document. The following code does just that but the formatting of the CV is messed up once it is inserted into the new document. Can I insert the file and keep the original formatting of the CV (I dont want to copy and paste from an open document):

objword1.Selection.InsertFile Filename:=cv1Address, _
    ConfirmConversions:=False, Link:=False, Attachment:=False

回答1:

I'm afraid that you can't use the InsertFile-method but have to open the file and copy&paste with wdFormatOriginalFormatting

I have found this:

Set rtffile = wdApp.Documents.Open(Filename:="C:\temp\rtf_stapler_problem\concat\cars2.rtf", ConfirmConversions:=False, ReadOnly:=True)
wdApp.Selection.WholeStory
wdApp.Selection.Copy
wdApp.ActiveWindow.Close savechanges:=wdDoNotSaveChanges
destdoc.Activate
wdApp.Selection.PasteAndFormat (wdFormatOriginalFormatting)
wdApp.Selection.InsertBreak Type:=wdSectionBreakNextPage

here