![]() |
#1
|
|||
|
|||
![]()
Due to some office moves, and two servers being combined into one, I now have a few hundred documents that are looking for a template file on a share that no longer exists.
For operational reasons, I cannot recreate this share in anyway (the machine name no longer exists locally). Word 2007 will open the documents, but slowly (pressing esc does work most of the time). What can I do to correct this to a local version of the template? Is there a way to open every file and correct the path? This could become rather annoying! I think I may have asked this before when the share was accessible, but over a slow VPN. Now, the share is NOT available at all. Thanks. :-) |
#2
|
|||
|
|||
![]()
Once a document is open, link it to the normal template. Make sure that the box to update styles from template is not checked. Save the document.
|
#3
|
|||
|
|||
![]()
The following macro should attach the normal template to the current document without updating styles.
Code:
Sub AttachNormalNoStyles() ' ' Attach Normal Template without updating Styles ' written by Charles Kenyon 2015-09-27 ' https://www.msofficeforums.com/word/28024-word-2007-template-missing-share.html ' With ActiveDocument .UpdateStylesOnOpen = False .AttachedTemplate = Application.NormalTemplate.FullName End With End Sub |
#4
|
|||
|
|||
![]()
Thanks :-)
Can I adapt that macro to attach the actual template, which is now on a local share? \\server\share\mytemplate.dot? |
#5
|
|||
|
|||
![]()
Yes. You need the full name and filepath inside quotation marks because it is a string.
|
#6
|
|||
|
|||
![]() Code:
Sub AttachNormalNoStyles() ' ' Attach Normal Template without updating Styles ' written by Charles Kenyon 2015-09-27 ' https://www.msofficeforums.com/word/28024-word-2007-template-missing-share.html ' With ActiveDocument .UpdateStylesOnOpen = False .AttachedTemplate = Application."\\server\share\template.dot" End With End Sub Ant I would put this macro into the template itself? |
#7
|
|||
|
|||
![]() Quote:
Try: Code:
.AttachedTemplate = "\\server\share\template.dot" I would put it in a Global Template with either a QAT button and/or a keyboard shortcut to trigger it. |
#8
|
|||
|
|||
![]()
Must admit, I am a little confused.
Which template to I add this to? If I open a saved file which has the rouge missing template attached, this is when I have trouble. Would I need to add this macro to everyone of these files? I open the files from windows explorer, not through file>open. Does that make sense? Thanks. |
#9
|
|||
|
|||
![]()
Again, I would put it in a Global Template, not a document template. See link in previous response.
You would run it every time you open a document and have the problem. You will have the problem only once with each document. You could add the line: activedocument.save at the end of the macro if you want. The macro is not added to the document. It is not added to the document's template. It is in a global template, always available. You run it when you run into problems and fix the link in the document to the template you want. |
#10
|
|||
|
|||
![]()
Oh, ok. Will give it a go, cheers.
Never used the global template, wasn't sure what you meant, but see, thanks. |
#11
|
|||
|
|||
![]() |
#12
|
||||
|
||||
![]()
When templates other than Word’s Normal template are used to create a document, the template’s path & name are stored with the document. If that path is a network path, a change to the server name will break the link. As you've observed, the result can be significant delays in opening the documents on the new server. See: http://support.microsoft.com/?kbid=830561. The same effect occurs when the file is opened on a computer attached to a different network.
The following macro can be used to update the template paths or, if a new template path can’t be found, to point it to Word’s Normal template. Code is included to restore the original date/time stamps of the updated files. In the code, simply replace however much of the old & new template paths differ in the OldServer and NewServer variables. Code:
Option Explicit Dim FSO As Object 'a FileSystemObject Dim oFolder As Object 'the folder object Dim oSubFolder As Object 'the subfolders collection Dim oFiles As Object 'the files object Dim i As Long, j As Long Sub Main() ' Minimise screen flickering Application.ScreenUpdating = False Dim StrFolder As String ' Browse for the starting folder StrFolder = GetTopFolder If StrFolder = "" Then Exit Sub i = 0: j = 0 ' Search the top-level folder Call GetFolder(StrFolder & "\") ' Search the subfolders for more files Call SearchSubFolders(StrFolder) ' Return control of status bar to Word Application.StatusBar = "" ' Restore screen updating Application.ScreenUpdating = True MsgBox i & " of " & j & " files updated.", vbOKOnly End Sub Function GetTopFolder() As String GetTopFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetTopFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function Sub SearchSubFolders(strStartPath As String) If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject") Set oFolder = FSO.GetFolder(strStartPath) Set oSubFolder = oFolder.subfolders For Each oFolder In oSubFolder Set oFiles = oFolder.Files ' Search the current folder Call GetFolder(oFolder.Path & "\") ' Call ourself to see if there are subfolders below Call SearchSubFolders(oFolder.Path) Next Set FSO = Nothing End Sub Sub GetFolder(StrFolder As String) Dim strFile As String strFile = Dir(StrFolder & "*.doc") ' Process the files in the folder While strFile <> "" ' Update the status bar is just to let us know where we are Application.StatusBar = StrFolder & strFile Call UpdateTemplateRefs(StrFolder & strFile) strFile = Dir() Wend End Sub Sub UpdateTemplateRefs(strDoc As String) ' This sub updates the template paths for files after a server ' change. Simply insert however much of the lower end of the ' server paths differ as the OldServer and NewServer variables. Dim OldServer As String, NewServer As String, strPath As String Dim oItem As Object, StrDtTm As String OldServer = "\\TSB\VOL1": NewServer = "\\TSLSERVER\Files" ' Store the file's current Date/Time stamp. If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject") Set oItem = FSO.GetFile(strDoc) StrDtTm = oItem.DateLastModified ' Open the document Documents.Open strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto With ActiveDocument If .ProtectionType = wdNoProtection Then ' Update the template path strPath = Dialogs(wdDialogToolsTemplates).Template If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then ' Update the file counter for changed files i = i + 1 ' Get the new template path & name strPath = NewServer & Mid(strPath, Len(OldServer) + 1) ' Check whether the template exists If Dir(strPath) <> "" Then ' If found, update the path .AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1) Else ' If not found, reset the template to 'Normal' .AttachedTemplate = "" ' Output an error report in the document from which the macro is run. ThisDocument.Range.InsertAfter vbCr & "Template: " & strPath & " not found for " & strDoc End If End If Else ' Output a 'protected' file report in the document from which the macro is run. ThisDocument.Range.InsertAfter vbCr & strDoc & " protected. Not updated." End If .Close SaveChanges:=True End With ' Update the main file counter j = j + 1 ' Let Word do its housekeeping DoEvents ' Reset the file's Date/Time stamp. Set oItem = FSO.GetFile(strDoc) If oItem.DateLastModified <> StrDtTm Then oItem.DateLastModified = StrDtTm Set oItem = Nothing End Sub Code:
Sub GetTemplateRef() With ActiveDocument MsgBox Dialogs(wdDialogToolsTemplates).Template End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]()
Thanks.
When I run the code to get the path, it just returns "normal" - The other path is not accessible, so I assume by the time word has opened it, it has changed the template? I thought I knew the old path, and tried using that, but it finishes the routine with "updated 0 of 250 files". Code:
Sub GetTemplateRef() With ActiveDocument MsgBox Dialogs(wdDialogToolsTemplates).Template End With End Sub |
#14
|
||||
|
||||
![]() Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
![]()
Thanks.
They still take ages to open? When I ran the small macro to display the existing template, I opened one of the documents. It took ages to load as usual, I assumed it would then change the template to the normal one automatically? Is this not why it displays as normal? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
New Template window in Word 2007 | kerrk | Word | 1 | 10-14-2011 02:06 AM |
Missing standard office tabs in ribbon for word 2007 | pugs | Word | 5 | 09-23-2011 12:12 AM |
Need help creating a word 2007 resume template | gsw1 | Word | 0 | 09-27-2010 06:29 PM |
How to share macros in Powerpoint 2007?? | proshop | PowerPoint | 0 | 12-20-2009 07:29 AM |
Editing Default Word 2007 Template | nhrav | Word | 0 | 09-16-2008 05:08 AM |