Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2017, 05:06 PM
vagabond's Avatar
vagabond vagabond is offline Moving body text from old files to new files (based on template) Windows 7 64bit Moving body text from old files to new files (based on template) Office 2013
Novice
Moving body text from old files to new files (based on template)
 
Join Date: May 2017
Location: The Neutral Zone, Third Rock & Sun
Posts: 2
vagabond is on a distinguished road
Default Moving body text from old files to new files (based on template)

I've done a brief search, wasn't able to come up with a solution - if I missed something, please point me in the right direction.


TLDR: Looking for a way to copy body text from one template to a new template on 500+ files automatically.


So I have about 500 files which are all based on a corporate letterhead template. The body of the text in these files is all I need to grab, not the headers or footers.



I need to change the letterhead, essentially, on each individual file, so that the new files contain the old text. I have done about twenty by copy-paste, but this is boredom in its finest and I am hoping there is, perhaps, a better way?

I need to maintain generalized formating and indentation, but match the new font style and size. There are no color issues.

This is being done on a W7KP machine running Office 2013.

Cheers and thanks!!

Jason
Reply With Quote
  #2  
Old 05-01-2017, 06:35 PM
Charles Kenyon Charles Kenyon is offline Moving body text from old files to new files (based on template) Windows 10 Moving body text from old files to new files (based on template) Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
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

What you want to do may be able to be done. It will depend on the ability of a macro to determine what it is that gets copied. Headers and footers are stored in section marks. There is one at the end of every document, but may be more in the middle. Sections / Headers and Footers in Microsoft Word (Ribbon Versions) If everything is one section, it should be relatively easy. That is not my forte' though.

However, I would suggest a paradigm shift for your new templates: use modular components stored in one or two locations. Build your templates using those components in a way that lets them be updated automatically by changes in the base.

I would suggest AutoText entries holding your letterhead, etc. Store those in a Global Template.

Then use an AutoText field to put the components into the templates. Finally, put an AutoNew macro in the templates to either lock or unlink the AutoText fields. Next time, you will need to only change the AutoText entries. All of the templates will update automatically when they are used to create new documents.
Automated Boilerplate Using Microsoft Word

I use something a bit more complex, in that I have a single document that contains parts marked by bookmarks. An AutoNew macro in each template calls them into the new document at a bookmarked location in the template. AutoText is easier but I had this set up before I realized that.

For documents based on my letterhead template, an Autonew macro tests the new document's template's name against a document variable that contains the name of the template that has the up-to-date material. If the document is based on any template other than that base one, the material is copied from the base one into the new document, replacing existing headers, footers, and styles. Because of the styles, I think that is a bit better than AutoText, but not a great deal better.
Reply With Quote
  #3  
Old 05-01-2017, 07:04 PM
vagabond's Avatar
vagabond vagabond is offline Moving body text from old files to new files (based on template) Windows 7 64bit Moving body text from old files to new files (based on template) Office 2013
Novice
Moving body text from old files to new files (based on template)
 
Join Date: May 2017
Location: The Neutral Zone, Third Rock & Sun
Posts: 2
vagabond is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
However, I would suggest a paradigm shift for your new templates: use modular components stored in one or two locations. Build your templates using those components in a way that lets them be updated automatically by changes in the base.
The only issues I see, in general, are offline use and decentralized use. These documents are medical policies and procedures, medical protocols, operations guidelines, etc.

Most will only receive the PDF version of the finished product; not the original Word.

That said, is it safe to assume that, in the creation of the PDF from the master document, all relevant sections are saved in and not linked to the final document? Does that even make sense? (I am fairly comfortable in Word, and office in general; but by no means an expert)

I am going now to check out the reference made. Thanks!!

Jason
Reply With Quote
  #4  
Old 05-01-2017, 07:23 PM
macropod's Avatar
macropod macropod is offline Moving body text from old files to new files (based on template) Windows 7 64bit Moving body text from old files to new files (based on template) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

In reality, all you should need to do is attach the new template to the existing files (or copies of them), then apply the new Style definitions to the documents you've attached the template to. For example, the following macro does that for all documents in a selected folder:
Code:
Sub UpdateDocumentTemplates()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      .AttachedTemplate = "C:\Templates\SomeTemplate.dotm"
      .CopyStylesFromTemplate (.AttachedTemplate.FullName)
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Simply change "C:\Templates\SomeTemplate.dotm" to suit your requirements.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-02-2017, 04:57 AM
Charles Kenyon Charles Kenyon is offline Moving body text from old files to new files (based on template) Windows 10 Moving body text from old files to new files (based on template) Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
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

Paul,

They are changing headers and footers. Attaching a new template will do nothing. They need to copy the body of the template into a new template with the new headers/footers.

Any chance you could come up with code that will:
For each template in a folder...
  1. Create a new template based on their new letterhead template
  2. Copy the body of the old template (absent last section mark) into the newly created template
  3. Save the new template with the same name as the old one in a second folder?
So long as their old ones have only one section, that should work. While I exect I could do this, it would be a week-long project for me and probably not as good as you could come up with in 10 minutes.
Reply With Quote
  #6  
Old 05-02-2017, 05:05 AM
Charles Kenyon Charles Kenyon is offline Moving body text from old files to new files (based on template) Windows 10 Moving body text from old files to new files (based on template) Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
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

Quote:
Originally Posted by vagabond View Post
The only issues I see, in general, are offline use and decentralized use. These documents are medical policies and procedures, medical protocols, operations guidelines, etc.
This should not be a problem. Again, if AutoText fields are used, those fields should be automatically unlinked by a macro. Thus, the actual content will be in the documuments but the field will be in the template. The global template should be copied/updated to each user's Word Startup Folder as a part of the network login procedure.

Quote:
Originally Posted by vagabond View Post
Most will only receive the PDF version of the finished product; not the original Word.
For this, you do not even need to unlink or lock the AutoText fields, when the PDF is made, it will contain your content. That PDF should be your local archival copy, though, not the Word file unless the fields are unlinked.

Quote:
Originally Posted by vagabond View Post

That said, is it safe to assume that, in the creation of the PDF from the master document, all relevant sections are saved in and not linked to the final document? Does that even make sense? (I am fairly comfortable in Word, and office in general; but by no means an expert)

I am going now to check out the reference made. Thanks!!

Jason
If you use AutoText and the AutoText field, the content of the field will be linked to the AutoText container unless and until you break that link. This is not reflected in PDF versions, which would contain the content.

If you use a macro to copy components from a source template, those components become part of the new document.
Reply With Quote
  #7  
Old 05-02-2017, 05:15 AM
Charles Kenyon Charles Kenyon is offline Moving body text from old files to new files (based on template) Windows 10 Moving body text from old files to new files (based on template) Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
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

One more note, if a macro is used to create the new templates, you will want to go over each one carefully. The chance that one or more will contain multiple sections (and thus different headers/footers) is high.
Reply With Quote
  #8  
Old 05-02-2017, 03:24 PM
macropod's Avatar
macropod macropod is offline Moving body text from old files to new files (based on template) Windows 7 64bit Moving body text from old files to new files (based on template) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Charles Kenyon View Post
They are changing headers and footers. Attaching a new template will do nothing.
Au contraire, the code I posted both attaches the new template and updates the Styles.

As for the headers/footers, if the content differs, the processing of that can be added to the code:
Code:
Sub UpdateDocumentsAndTemplates()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
Dim strTmplt As String, wdTmp As Document, HdFt As HeaderFooter
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strTmplt = "C:\Templates\SomeTemplate.dotm"
Set wdTmp = Documents.Open(strTmplt)
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      .AttachedTemplate = strTmplt
      .CopyStylesFromTemplate (strTmplt)
      With .Sections(1)
        For Each HdFt In .Headers
          If HdFt.Exists Then
            If wdTmp.Sections(1).Headers(HdFt.Index).Exists Then
              HdFt.Range.FormattedText = wdTmp.Sections(1).Headers(HdFt.Index).Range.FormattedText
            End If
          End If
        Next
        For Each HdFt In .Footers
          If HdFt.Exists Then
            If wdTmp.Sections(1).Footers(HdFt.Index).Exists Then
              HdFt.Range.FormattedText = wdTmp.Sections(1).Footers(HdFt.Index).Range.FormattedText
            End If
          End If
        Next
      End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to find/replace text in many word files - but text is in embedded word files semple.13 Word VBA 5 11-03-2015 01:20 PM
Moving body text from old files to new files (based on template) Moving Multiple Hyperlinked Files around cole790 Word 1 12-08-2013 03:55 PM
Merging pst files and moving to NAS drive riteoh Outlook 0 10-02-2012 05:20 AM
Moving body text from old files to new files (based on template) Moving files from one template to another Stephen0352 Word 4 03-05-2012 01:29 AM
moving data files g48dd Outlook 2 06-17-2011 01:18 PM

Other Forums: Access Forums

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