#1
|
|||
|
|||
Automatically Using Complex headers and footers in new documents
I manage multiple Word document templates for my company When I say templates, I don't mean Word templates, but Word documents that contain code that our system, essentially Mail Merges from system data into finished Word documents. So, my resultant document is referred to as a template and my starting document Ive called a Master document There are many hundreds of these To make life easier I wondered if there was a way to automatically copy the complex header of a Master document into 10s of Word Document templates I've attached a current 'Master' document (Master UK.docx) and one example of the Template I need to produce (585prop01.docx). It's not hard to Ctrl+C and Ctrl+v across from one document to another but often I have 10s (sometimes 100s) of documents to update if the business wants to change something, ie the logo or the layout. (And this is without talking about the Footers or the Page 2 headers which is different Im looking to see if theres a way to apply some kind of automation to this as it's extremely labour intensive and time consuming. To make it worse the templates are password protected, although these is a 'connection' between the document name and the password |
#2
|
|||
|
|||
I do this.
I have one document that holds the header and footer in bookmarks. My templates have an AutoNew macro that copies those bookmarks into the header and footer area in the document, overwriting any current content. You could, instead, store your header/footer as AutoText in a Global Template. Then use AutoText fields in your templates/documents. You can use AutoNew / AutoOpen macros to update those fields. That is better, IMO, than using bookmarked text. However, someone needs to know what to change when changes are needed. In either of these, you edit the base and it gets updated when the template/documents are used. |
#3
|
|||
|
|||
Very helpful
Hi Charles, very interesting and helpful, thank you
Some things there that I didn't know and, therefore haven't tried but I'll give them a go Thanks again |
#4
|
|||
|
|||
Just a quick follow up
My headers are ludicrous, There is so much code that it 'overflows' the header area and 'disappears' into the body (see image)
Of course once the document gets 'mailmerged' by our system then all that appears in the right jand column (under the logo) is a regular address; but the code needed to capture this is really excessive and what you can't see in the image is a some more rows for capturing the remainder of the address, plus office email address, phone IS there a way to only see the header in Word display (in the same way you avoid seeing Headers in draft view), so the whole header bceomes visible for editing; in essence moving the horizontal row (named page header) down to reveal the whole thing. As an indication, this is what the entire header code looks like (Yeah I know I can shift the margin of the right column temporarily so I can see the whole thing, but then I have overlapping text from the left text box and DRAFT 'watermark' and it all becomes very messy) please see below. When it is crammed in to the necessary narrow area below the logo it's a 'mare: <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficeAddress1Event ")%><%if(!applyEventToBusinessEntity(getEformObjec t(pageContext),"McLarens.DocumentTags.OfficeAddres s2Event").equals("")){%> <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficeAddress2Event ")%><%}%><%if(!applyEventToBusinessEntity(getEform Object(pageContext),"McLarens.DocumentTags.OfficeA ddress3Event").equals("")){%>, <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficeAddress3Event ")%><%}%> <%if(!applyEventToBusinessEntity(getEformObject(pa geContext),"McLarens.DocumentTags.OfficeAddress4Ev ent").equals("")){%><%=applyEventToBusinessEntity( getEformObject(pageContext),"McLarens.DocumentTags .OfficeAddress4Event")%> <%}%><%=applyEventToBusinessEntity(getEformObject( pageContext),"McLarens.DocumentTags.OfficeCityEven t")%>, <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficePostCodeEvent ")%> Tel: <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficePhoneEvent")% > <%=applyEventToBusinessEntity(getEformObject(pageC ontext),"McLarens.DocumentTags.OfficeEmailEvent")% > 2 July 2022 Our Ref: <%=setLevel()%><%=getValue("CaseNumber")%> |
#5
|
|||
|
|||
Sorry, one last question (I hope)
Those AutoNew/AutoOpen macros, could you share the code, please
Thanks again |
#6
|
|||
|
|||
First, Insert > Header > Edit Header
See:
Here is my page on AutoCorrect, Auto Text and Building Blocks. Automated Boilerplate Using Microsoft Word |
#7
|
|||
|
|||
I am going to focus on the AutoText method since, IMO, it is the most elegant. Refer to the chapter on boilerplate. You want to have unique names for your entries that will not normally come up in typing. I often use underscores at the beginning of a name and put them in a category that will be at the end of the alphabet so that I do not see these entries in the list. You can and probably should use one of the custom galleries rather than AutoText.
Building Blocks & AutoText by Greg Maxey I will be assuming Custom Gallery 5, although it does not matter for the update macros. |
#8
|
|||
|
|||
An AutoNew macro or the corresponding Document_New procedure go in the template.
Run a macro automatically when a document is created, opened or closed Assuming that the Document_New procedure is in the ThisDocument module of your template... Code:
Sub Document_New() ' Charles Kenyon 2022-07-02 ' Written by Charles Kyle Kenyon 2 July 2022 ' assistance from Jezebel ' All Story Field Updater - AutoText fields - then unlinks Dim oField As Field Dim oStory As range ' On Error Resume Next For Each oStory In ActiveDocument.StoryRanges ' This goes into headers and footers as well as the regular document Do For Each oField In oStory.Fields If oField.Type = wdFieldAutoText Then oField.Update oField.Unlink ' this will no longer be a field End If Next oField Set oStory = oStory.NextStoryRange Loop Until oStory Is Nothing Next oStory Set oStory = Nothing On Error GoTo -1 End Sub |
#9
|
|||
|
|||
Thank you so much for your time and help
|
#10
|
|||
|
|||
You are welcome.
P.S. Be careful with the term "Master Document." That is Word's jargon for a "feature" that does not work very well. Master Documents "Feature" in Microsoft Word |
Tags |
automation, headers, master |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Bulk/Batch update Word documents Headers and footers | troyw | Word VBA | 8 | 05-05-2021 07:17 PM |
a code that can change the layout for the headers and footers on each page automatically | gmbh | Word VBA | 1 | 07-31-2014 04:24 AM |
Macro for find/replace (including headers and footers) for multiple documents | jpb103 | Word VBA | 2 | 05-16-2014 04:59 AM |
Odd and Even Headers/Footers | sarineochaos | Word | 1 | 02-04-2014 06:15 PM |
Headers and Footers | OverAchiever13 | Word | 1 | 05-27-2010 01:30 PM |