![]() |
|
#1
|
|||
|
|||
|
Hi everyone, I have almost 1000 documents that have a template attached to them. The template has recently been updated so now whenever we open the documents, it says "your template needs to be updated." This is part of our coding, so I expect to see this warning. You click "ok" and then save your document, and now your template is updated. I was wondering if there is a way to remove the old template and then apply the new one to all 1000 documents without going 1 by 1. The actual template file is the same name, but has been updated (file.dot). We are running Office 2007 - the files are technically stored on a SharePoint, but I can extract them\upload new ones as needed. Thanks much!! |
|
#2
|
||||
|
||||
|
Hi ohmzoned,
Assuming all files in a given folder should have the same template, try: Code:
Sub AttachNewTemplate()
Application.ScreenUpdating = False
Dim strFolder As String, strTmplt As String, strFile As String, wdDoc As Document
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.AllowMultiSelect = False
.Filters.Add "All Word Templates", "*.dot; *.dotx; *.dotm", 1
If .Show = -1 Then
strTmplt = .SelectedItems(1)
Else
Exit Sub
End If
End With
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
' Create a temporary Word session to do the processing
Dim wdTmp As New Word.Application
wdTmp.Visible = False
'wdTmp.DisplayAlerts = wdAlertsNone
While strFile <> ""
Set wdDoc = wdTmp.Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
wdDoc.AttachedTemplate = strTmplt
wdDoc.Close SaveChanges:=True
strFile = Dir()
Wend
Set wdDoc = Nothing: Set wdTmp = 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] |
|
| Tags |
| templates, word 2007 |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2003 event ID 1000
|
djsep3763 | Outlook | 1 | 03-18-2012 06:06 PM |
| How to attach an action to a hyperlink | tapty | PowerPoint | 0 | 01-27-2012 05:25 AM |
Template with automatic text input from seperate documents!
|
word | Word | 1 | 06-03-2011 02:45 PM |
| Avery Labels Numbered 1 through 1000+? | kteh54 | Word | 0 | 03-03-2010 06:06 PM |
| Template "File In Use" when opening 2 documents based on the same template | wendt | Word | 5 | 12-15-2009 12:37 AM |