PDA

View Full Version : Merging Word Documents From VBA



CDLM14
03-14-2014, 05:45 AM
Hi all!

I am working on a project which requires me to merge word documents from VBA. Something like "Word Doc1 + Word Doc2 = Word Doc3". While doing a search of the forums I found the following code posted by SnB:

Sub M_snb()
With Getobject("G:\OF\doc1.docx")
.content.insertafter getobject("G:\OF\doc2.docx").content
.saveas2 "G:\doc3.docx",12
.close False
End With
End Sub

This is wonderful. However it only transfers the content of the document and not any formatting or styles.

Does anyone have an idea as to how I can go about this?

Thanks very much!

psctornado
03-14-2014, 05:54 AM
Isn't this more of word forum question than excel? You may be able to get better support on that end.

CDLM14
03-14-2014, 06:24 AM
I need excel VBA code not word VBA

snb
03-14-2014, 09:07 AM
Please use code tags !


Sub M_snb()
With Getobject("G:\OF\doc1.docx")
.content.insertafter getobject("G:\OF\doc2.docx").content.formattedtext
.saveas2 "G:\doc3.docx",12
.close False
End With
End Sub

CDLM14
03-14-2014, 10:00 AM
thanks snb!