Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2022, 10:37 AM
rogerbowering rogerbowering is offline Automatically Using Complex headers and footers in new documents Windows 10 Automatically Using Complex headers and footers in new documents Office 2010 32bit
Novice
Automatically Using Complex headers and footers in new documents
 
Join Date: Apr 2017
Posts: 15
rogerbowering is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-01-2022, 09:30 PM
Charles Kenyon Charles Kenyon is offline Automatically Using Complex headers and footers in new documents Windows 11 Automatically Using Complex headers and footers in new documents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #3  
Old 07-02-2022, 03:43 AM
rogerbowering rogerbowering is offline Automatically Using Complex headers and footers in new documents Windows 10 Automatically Using Complex headers and footers in new documents Office 2010 32bit
Novice
Automatically Using Complex headers and footers in new documents
 
Join Date: Apr 2017
Posts: 15
rogerbowering is on a distinguished road
Default 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
Reply With Quote
  #4  
Old 07-02-2022, 03:54 AM
rogerbowering rogerbowering is offline Automatically Using Complex headers and footers in new documents Windows 10 Automatically Using Complex headers and footers in new documents Office 2010 32bit
Novice
Automatically Using Complex headers and footers in new documents
 
Join Date: Apr 2017
Posts: 15
rogerbowering is on a distinguished road
Default 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")%>
Attached Images
File Type: jpg Header 1.jpg (128.0 KB, 23 views)
Reply With Quote
  #5  
Old 07-02-2022, 03:57 AM
rogerbowering rogerbowering is offline Automatically Using Complex headers and footers in new documents Windows 10 Automatically Using Complex headers and footers in new documents Office 2010 32bit
Novice
Automatically Using Complex headers and footers in new documents
 
Join Date: Apr 2017
Posts: 15
rogerbowering is on a distinguished road
Default Sorry, one last question (I hope)

Those AutoNew/AutoOpen macros, could you share the code, please

Thanks again
Reply With Quote
  #6  
Old 07-02-2022, 10:03 AM
Charles Kenyon Charles Kenyon is offline Automatically Using Complex headers and footers in new documents Windows 11 Automatically Using Complex headers and footers in new documents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

First, Insert > Header > Edit Header
See:
I will scrounge some macros. Again, I want to stress where possible using templates rather than documents. Reusing documents is a recipe for problems. About the only documents I reuse are logs where I keep date stamping and adding information.


Here is my page on AutoCorrect, Auto Text and Building Blocks.
Automated Boilerplate Using Microsoft Word
Reply With Quote
  #7  
Old 07-02-2022, 10:19 AM
Charles Kenyon Charles Kenyon is offline Automatically Using Complex headers and footers in new documents Windows 11 Automatically Using Complex headers and footers in new documents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #8  
Old 07-02-2022, 10:39 AM
Charles Kenyon Charles Kenyon is offline Automatically Using Complex headers and footers in new documents Windows 11 Automatically Using Complex headers and footers in new documents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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
This macro will update all AutoText fields in a new document created from the template and then remove the field leaving the results. If documents are going to someone else, you do not want these fields in the document, you want what they produce. This could be restricted to headers or footers but I know of no reason to do so.
Reply With Quote
  #9  
Old 07-03-2022, 10:39 PM
rogerbowering rogerbowering is offline Automatically Using Complex headers and footers in new documents Windows 10 Automatically Using Complex headers and footers in new documents Office 2010 32bit
Novice
Automatically Using Complex headers and footers in new documents
 
Join Date: Apr 2017
Posts: 15
rogerbowering is on a distinguished road
Default

Thank you so much for your time and help
Reply With Quote
  #10  
Old 07-04-2022, 07:05 AM
Charles Kenyon Charles Kenyon is offline Automatically Using Complex headers and footers in new documents Windows 11 Automatically Using Complex headers and footers in new documents Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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

Tags
automation, headers, master

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Using Complex headers and footers in new documents 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
Automatically Using Complex headers and footers in new documents 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:35 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