Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2019, 06:07 AM
Florre Florre is offline Merging a Word document from two or more document templates Windows 10 Merging a Word document from two or more document templates Office 2019
Novice
Merging a Word document from two or more document templates
 
Join Date: Jun 2019
Location: Sweden
Posts: 1
Florre is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-26-2019, 03:20 PM
macropod's Avatar
macropod macropod is offline Merging a Word document from two or more document templates Windows 7 64bit Merging a Word document from two or more document templates Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Tags
mergins files



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging a Word document from two or more document templates Merging two Word documents: 2nd document not maintaining original font type and font size Swarup Word 31 08-28-2018 06:55 PM
Merging a Word document from two or more document templates Merging different sections in one document apanbasu Word 5 03-04-2017 07:18 PM
Merging a Word document from two or more document templates Macro for opening a blank Word document from My Templates (Mac) yinswenti Word VBA 6 02-08-2015 08:10 AM
Merging a Word document from two or more document templates 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft