Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Mail Merge Generated Document - How to keep field in a paragraph

Posted on 2013-05-14
Medium Priority
Last Modified: 2013-05-21

Pursuing an idea to generate some documentation via a workbook and have hit a small curiosity I don't know how to fix.

In the Word document (merge template) I have a paragraph under a table that is designed to be Table 1 ... then (automatically) Table 2 ... under the next table and so on.

If I copy/paste the template table & paragraph it works fine.

However, as soon as I generate a new document from the template that field in the generated paragraphs reverts to plain text and I've lost the ability for it to auto-number itself.

What do I need to do to retain this auto-numbering capability.

sample workbook (with macro/template) attached (.xslm)

follows on from:

Word & Excel 2010:
Question by:PortletPaul
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
LVL 76

Accepted Solution

GrahamSkan earned 2000 total points
ID: 39167484
From the start, most of Word's features (macros, styles, bookmarks. fields, etc.) have been there simply as aids to producing a well-formatted printed document. The output from a mail merge is expected to be the end of the production process, so all bookmarks are dropped, and most fields converted to fixed text.

This is not a problem if the destination is fax, printer or email, but the possibility of outputting to another document does raise expectations. You would either have  to use a VBA emulation of mail merge, or do some post-merge work (manual or programmatic) to meet those expectations.
LVL 49

Author Comment

ID: 39167542
right, I don't consider mail merge to be the end of the chain here, just part of the equation

so, either I emulate mail merge to build multiple tables in a loop... yuk

or 'post process', so the desire now is, what macro magic would match the style of these paragraphs and re-insert the 'field' for auto numbering behaviour?

a sample would probably be sufficient - I can fix the details
LVL 49

Author Comment

ID: 39167557
maybe I need to rethink my attitude to using Mail Merge?

any recommended sample macros that would repeat a (table+paragraph) structure to a new document?

I do have another need to reproduce rows of a table that Mail Merge does not do very well (it wants to repeat the table headings).

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

LVL 76

Assisted Solution

GrahamSkan earned 2000 total points
ID: 39167630
We don't know your wider objective, but it sounds as if you might find building blocks useful.
You can create the fully formatted table and field, select it and save it as a 'Quick Part'. Then you can run some code like this which will add another such block at the end of the current document.
Private Sub InsertBB()
Dim objTemplate As Template
Dim objBB As BuildingBlock

Set objTemplate = Templates(1)
Set objBB = objTemplate.BuildingBlockEntries("TablePlusTitle")

objBB.Insert ActiveDocument.Bookmarks("\EndOfDoc").Range
End Sub

Open in new window

LVL 49

Author Comment

ID: 39167677
rudimentary I know, but the broader picture was hinted at in the earlier question...

The overall objective is to help drive accurate documentation that evolves over time with numerous cross-references, from requirements to test plans and operational instructions

This is performed by a broad geographic spread of individuals (and translations are required)

The concept (and that's all it is right now) is to maintain all (or most) of the cross-referencing material in a workbook instead of Word docs - then derive parts of the needed Word docs when it is logical to do so. Ideally there would be some more robust toolset to undertake this - but there isn't - so it's the ubiquitous Excel/Word I'm resorting to.

The starting point is that I do not want to commence or control this from Word - it must be controlled from the Workbook - and Word elements generated from it.

nb: Not whole (final) documents are intended from the Workbook - just the numerous tables (with cross-references) that can be merged (manually) into the manually prepared deliverable documents.

appreciate any guidance really - right now this is conceptual - I want to build enough to be a 'proof of concept' really. samples and/or good references are always welcomed - I'm not expecting vba scripts of several 1000 lines :) - well not on the basis of one question anyway.

Not sure if this helps at all.

back to a question - where would the 'Quick Parts' be stored? and how are they referenced? (looks like I get to name them). Would these (or could these) be stored in a single embedded word doc?

ps: it's been many many years since I delved into VBA, but I'm not afraid of it, and once I get into the swing of it could be considered better than beginner (well I hope so).
LVL 76

Assisted Solution

GrahamSkan earned 2000 total points
ID: 39167739
It might be worth assembling a structured document for use as the mail merge main document and then executing the merge.

With or without mail-merge, you will almost certainly need some VBA code.

If you need any help with code is solely or largely Word-orientated, can you remember to add Word to the relevant Zones? It might help to get more Word experts interested.
LVL 49

Author Comment

ID: 39167762
I did include Word as a topic - didn't I?

>> I will stress - the control of execution MUST be from Excel, NOT Word... on this I will not bend.

My additional desire is to embed any Word files(s) required into the Workbook so that versioning and distribution are simplified
e.g. v1 workbook has v1 embedded document and can survive on its own merits after v1.1 is issued and so on.
LVL 76

Assisted Solution

GrahamSkan earned 2000 total points
ID: 39167970
Yes, sorry. I was looking in the wrong place.

In VBA, you can work on documents (including workbooks, powerpoint presentations, outlook items &c) belong to any Office application from any other Office application.

The Word user interface only allows saving a selection as a Quick Part to a template. I'm pretty sure that can be worked around, e.g. renaming the template as a document later. There isn't a fundamental difference between a document and a template - just name and usage. However, if mail merge is to be abandoned at the initial stage, embedded templates would be more logical.

Actually, you might be able to use one template only, containing all the blocks, but with graphic images of what each button will add, positioned where the document objects currently are.
LVL 49

Author Comment

ID: 39171246
thanks for the tip on 'QuickParts' to be frank that entire piece of Word had escaped my attention. This proved to be an amazing reference on that topic:

But, I now have  another concern. If QuickParts are stored in the Normal.dot or Building Blocks.dotx than these could be really troublesome for my intended purpose (broad distribution without complex dependencies).

Additionally, while that URL above provided some VBA related to QuickParts, I still haven't seen one which:
a. chooses a quickpart, and
b. uses that quickpart like a mail merge template (i.e. repeats the quickpart filled-in with data from Excel)

Do you really believe defining quickparts can work via an embedded document in Excel
(and used by someone half-way around the world)?
LVL 49

Author Closing Comment

ID: 39183302
I'm not at all sure if quickparts will survive within a document embedded into Excel, but at least i now know something about their existence  thanks for that.

Thanks for the various pointers. I will still be working on this concept on  off for a while I think and will probably be back for more questions.

LVL 76

Expert Comment

ID: 39183752
Thanks & good luck

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question