#1
|
|||
|
|||
Merging a Word document from two or more document templates
I have made three templates; one Agreement, one pricelist appendix and one condition appendix. I have a Word form with VBA code that sometimes need one or two of the extra appendix merged and sometimes not. How do I make a new document that, if necessary, adds the pricelist and/or the agreement at the end? I have find a code that merges all documents in one folder, but to get that to work I must do all these parts: 1. Make all temporary documents from the different templates 2. Make a temporary folder 3. Save the documents in the folder 4. Merge the documents 5. Save the new document in the folder I need it in 6. Delete the documents in the temporary folder 7. Delete the temporary folder Is there any way to do this without making temporary files and folder? This is the code i found: Code:
Sub MergeDocuments() Application.ScreenUpdating = False MyPath = ActiveDocument.Path MyName = Dir(MyPath & "\" & "*.docx") i = 0 Do While MyName <> "" If MyName <> ActiveDocument.Name Then Set wb = Documents.Open(MyPath & "\" & MyName) Selection.WholeStory Selection.Copy Windows(1).Activate Selection.EndKey Unit:=wdLine Selection.TypeParagraph Selection.Paste i = i + 1 wb.Close False End If MyName = Dir Loop Application.ScreenUpdating = True End Sub |
#2
|
||||
|
||||
Why not start with a single template that has all the potential content, bookmark the bits that might get deleted and, if they're unwanted simply delete the bookmarked range(s). Alternatively, save the potential extra content as custom quick parts in the base template, then insert them from there as/when necessary?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
mergins files |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merging two Word documents: 2nd document not maintaining original font type and font size | Swarup | Word | 31 | 08-28-2018 06:55 PM |
Merging different sections in one document | apanbasu | Word | 5 | 03-04-2017 07:18 PM |
Macro for opening a blank Word document from My Templates (Mac) | yinswenti | Word VBA | 6 | 02-08-2015 08:10 AM |
Merging Word documents and keeping the formatting exactly as it appears in the original document | NovaScotia | Word | 4 | 01-21-2015 11:44 PM |
Merging multiple records into one document | LaniKaye | Mail Merge | 3 | 10-28-2014 05:56 PM |