Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2020, 09:19 AM
NicB NicB is offline VBA to add final touches to merged document, after running MailMergeToDoc script Windows 10 VBA to add final touches to merged document, after running MailMergeToDoc script Office 2016
Novice
VBA to add final touches to merged document, after running MailMergeToDoc script
 
Join Date: Apr 2018
Posts: 17
NicB is on a distinguished road
Default VBA to add final touches to merged document, after running MailMergeToDoc script

Hi



Thanks to macropod's helpful mail merge instructions/tutorial on this forum, I have successfully built a directory mail merge using data from an Excel spreadsheet. This merge is basically taking the data out of the Excel spreadsheet and merging it with a series of grouped tables in Word formatted in a much more presentable manner. Macropod's MailMergeToDoc script is set to run automatically once the merge has finished, to remove the blank rows.

In an ideal world, I would like to expand on this script but have no real knowledge of VBA and was wondering if I could ask for some assistance.

What I would like to achieve is that once the MailMergeToDoc script has finished, the following happens automatically:

1. A Section break is added at the beginning of the document and at the end of the document, with 1cm margins Top, Bottom, Left and Right, and the Headers/Footers set to 0.5cm from edge. The headers/footers for the cover pages are blank, so the header/footer settings for these two sections should not be linked to the previous.

3. A custom cover page named 'Front Cover' is added to the first page (Section 1) . This cover page has been included as a Custom Cover Page Building Block, in the Category 'Schedules' within the template that is attached to the merged document.

4. A different custom cover page, named 'Back Cover' is added to the last page of the document (Section 3). Again, this building block is saved in the 'Schedules' Category that I have created in the template attached to the document.

5. In Section 2, a custom header, named 'Joint Header' and footer 'Joint Footer' is added which is not linked to the previous section

Is such a macro possible and if so, is anyone able to to assist/guide me with regards to building it?

Thank you very much in advance.
Reply With Quote
  #2  
Old 09-02-2020, 05:47 PM
Guessed's Avatar
Guessed Guessed is offline VBA to add final touches to merged document, after running MailMergeToDoc script Windows 10 VBA to add final touches to merged document, after running MailMergeToDoc script Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Where possible, you should make use of the existing features before going to code. It looks like you jumped #2 but #1 and #3 could be combined if the Cover Page you have stored includes a section break. The section break contains the page setup of the section that PRECEDES it so including the section break at the end of the Cover Page therefore includes the page setup and header/footer settings of the Cover Page.

Similarly, if you wanted to include a section break at the start of the "Back Cover" building block, it would set the page setup and header/footer settings of Section 2 - effectively merging #3 and #4 requests.

I would have to ask why you don't simply include the cover and back page in the merge source document before resorting to code at all. I assume it has to get added post-processing because of your script.

Adding a BuildingBlock at a particular location is straightforward but you need to know a few things about it: which template is it stored in, what is the building block's type, category and name.

Code:
Dim aRng as Range
Set aRng = ActiveDocument.Range(0,0)   ActiveDocument.AttachedTemplate.BuildingBlockTypes(wdTypeCustomCoverPage).Categories("General").BuildingBlocks("Front Cover").Insert Where:=aRng, RichText:=True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to add final touches to merged document, after running MailMergeToDoc script Delete newsletter formatting for final page of document rachmc Word 1 11-06-2017 12:22 AM
Unmark Final document mmineyev Word 2 10-01-2017 07:48 PM
How to generate a word document with a table-script valdavaux Word 1 09-17-2017 03:32 PM
VBA to add final touches to merged document, after running MailMergeToDoc script After Accepting changes in Document and Final Markup Crystaldiamond Word 1 01-11-2015 04:00 PM
Make text strikeouts visible in final document klkyde Word 0 12-16-2014 11:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:49 PM.


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