Microsoft KB Archive/830561

= Documents that have attached templates take a long time to open in Word 2002 and in Word 2003 =

Article ID: 830561

Article Last Modified on 11/26/2007

-

APPLIES TO

 Microsoft Office Word 2003 Microsoft Word 2002 Standard Edition, when used with:  Microsoft Windows XP Home Edition

 Microsoft Windows XP Professional 

-





SYMPTOMS
When you open a Microsoft Word 2002 document or a Microsoft Word 2003 document on a computer that has Microsoft Windows XP installed, the document may take longer then expected to open. For example, the document may take 5 to 10 minutes to open.

Note You will not have this problem if you run Word on the Windows Vista operating system.

<div class="cause_section">

CAUSE
This symptom may occur if the document has a template attached or linked and one of the following conditions is true:
 * The attached template, its folder, or its share is missing.
 * The attached template has been moved.
 * The attached template has been renamed.

When a Word template is missing, Windows XP will try to locate the missing template multiple times. The process of locating a missing template may cause a Word document to take longer than expected to open.

It will take longer to open the document when you are connected to a network compared to when you are disconnected from the network.

<div class="resolution_section">

RESOLUTION
To resolve this issue, install the fix that is described in the following Microsoft Knowledge Base article.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

823372 Your Word documents take a long time to open when they have attached templates

Note After you apply this fix, you must create a registry key to activate it.

<div class="workaround_section">

WORKAROUND
To work around this problem on a computer with Windows XP installed, use one of the following methods as appropriate for your situation:
 * Method 1: Attach the template from a new location, or attach the global template (Normal.dot).
 * Method 2: Use a custom Visual Basic Application to change the attached template to the global template (Normal.dot ) when a new document is opened.
 * Method 3: Create a Microsoft Visual Basic for Applications (VBA) macro that loops through all the documents in a folder and changes the old server name with the new server name
 * Method 4: Create a VBA Macro that loops through all the documents in a folder and changes the old server name with the global template (Normal.dot )
 * Method 5: Rename the server, the share, or the folder to the original name

Method 1: Attach the Template from a New Location
Open the document in Microsoft Word. Wait until the document is open. After the document is open, attach the template from the new location. Or, change the template to the global template, Normal.dot. To attach the template, follow these steps:
 * 1) On the Tools menu, click Templates and Add-ins.
 * 2) In the Templates and Add-ins dialog box, click Attach.
 * 3) In the Attach Template dialog box, select the template that you want, and then click Open.
 * 4) In the Templates and Add-ins dialog box, click OK.

back to the top

Method 2: Use a custom Visual Basic Application to change the attached template to the global template (Normal.dot ) when a new document is opened
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Use a custom solution to change the attached template to the Global Template (Normal.dot ) when a new document is opened.

Note Make sure that macro security is set to medium or low.

To create the custom solution in Microsoft Visual Basic 6, follow these steps: <ol> Open a new Standard.exe project.</li> On a User Form, add the following components:  One list box</li> Two text boxes</li> Four command buttons</li> Two labels</li></ul> </li> Set a reference to the Microsoft Scripting Runtime (Scrun.dll).</li>  Copy and paste the following code in a user form: Option Explicit

Private Const BIF_RETURNONLYFSDIRS = 1 Private Const BIF_DONTGOBELOWDOMAIN = 2 Private Const MAX_PATH = 260 Private Declare Function SHBrowseForFolder Lib &quot;shell32&quot; _ (lpbi As BrowseInfo) As Long Private Declare Function SHGetPathFromIDList Lib &quot;shell32&quot; _ (ByVal pidList As Long, _  ByVal lpBuffer As String) As Long Private Declare Function lstrcat Lib &quot;kernel32&quot; Alias &quot;lstrcatA&quot; _ (ByVal lpString1 As String, ByVal _  lpString2 As String) As Long

Private Type BrowseInfo hWndOwner     As Long pIDLRoot      As Long pszDisplayName As Long lpszTitle     As Long ulFlags       As Long lpfnCallback  As Long lParam        As Long iImage        As Long End Type

Public fso As New FileSystemObject Dim fld As Folder

Private Sub cmdEnd_Click End End Sub

Private Sub cmdSource_Click ' Opens a Treeview control that displays the directories in a computer.

Dim lpIDList As Long Dim sBuffer As String Dim szTitle As String Dim tBrowseInfo As BrowseInfo

szTitle = &quot;This is the title&quot; With tBrowseInfo .hWndOwner = Me.hWnd .lpszTitle = lstrcat(szTitle, &quot;&quot;) .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN End With

lpIDList = SHBrowseForFolder(tBrowseInfo) If (lpIDList) Then sBuffer = Space(MAX_PATH) SHGetPathFromIDList lpIDList, sBuffer sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1) frmFSO.txtSearch.Text = sBuffer End If End Sub

Private Sub cmdTarget_Click

' Opens a Treeview control that displays the directories in a computer.

Dim lpIDList As Long Dim sBuffer As String Dim szTitle As String Dim tBrowseInfo As BrowseInfo

szTitle = &quot;This is the title&quot; With tBrowseInfo .hWndOwner = Me.hWnd .lpszTitle = lstrcat(szTitle, &quot;&quot;) .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then sBuffer = Space(MAX_PATH) SHGetPathFromIDList lpIDList, sBuffer sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1) End If End Sub

Private Sub Command1_Click Dim nDirs As Long, nFiles As Long, lSize As Currency Dim sDir As String, sSrchString As String Dim nTime Dim ntime2 Dim nOk As Integer Dim fileNumber As Integer Dim oWord As Object Dim strServer As String Set oWord = CreateObject(&quot;Word.Application&quot;) strServer = txtOldServer.Text nTime = Time fileNumber = FreeFile List1.Clear Open &quot;C:\ChangeTemplate.log&quot; For Append As #fileNumber Write #fileNumber, &quot;Start:&quot; & &quot; &quot; & nTime Close #fileNumber 'Enter the top-level directory to start the search. sDir = txtSearch.Text 'Enter the type of files, such as *.doc for Word documents sSrchString = &quot;*.doc&quot; MousePointer = vbHourglass

'The label shows the current subfolder being searched. Label1.Caption = &quot;Searching Folder: &quot; & vbCrLf & UCase(sDir) & &quot;...&quot; lSize = FindFile(sDir, sSrchString, nDirs, nFiles, strServer, oWord) MousePointer = vbDefault ntime2 = Time 'Opens text file to show the stop time and the total numbers of 'files that were found. Open &quot;C:\ChangeTemplate.log&quot; For Append As #fileNumber Write #fileNumber, &quot;Stop:&quot; & &quot; &quot; & ntime2 & &quot; &quot; & _ &quot;Time to Complete the Changes: &quot; & _ Format(ntime2 - nTime, &quot;nn:ss&quot;) & vbCrLf _ & Str(nFiles) & &quot; files found in&quot; & Str(nDirs) & _ &quot; directories&quot; Close #fileNumber ' Debug.Print &quot;Stop:&quot; & &quot; &quot; & ntime2 Label1.Caption = &quot;Done&quot; If Label1.Caption = &quot;Done&quot; Then Command2.Enabled = True MsgBox &quot;Done&quot; oWord.Quit Set oWord = Nothing End Sub

Private Function FindFile(ByVal sFol As String, sFile As String, _  nDirs As Long, nFiles As Long, strOServer As String, oWrd As Object) _ As Currency Dim tFld As Folder, tFil As File, FileName As String Dim strFileName As String Dim fileNumber As Integer On Error GoTo Catch Set fld = fso.GetFolder(sFol) FileName = Dir(fso.BuildPath(fld.Path, sFile), vbNormal Or _     vbHidden Or vbSystem Or vbReadOnly) While Len(FileName) <> 0 FindFile = FindFile + FileLen(fso.BuildPath(fld.Path, FileName)) nFiles = nFiles + 1 List1.AddItem fso.BuildPath(fld.Path, FileName) ' Load ListBox strFileName = fld.Path & &quot;\&quot; & FileName '==     ChangeTemplate strFileName, strOServer, oWrd FileName = Dir ' Get next file DoEvents Wend Label1 = &quot;Searching &quot; & vbCrLf & fld.Path & &quot;...&quot; nDirs = nDirs + 1

If fld.SubFolders.Count > 0 Then For Each tFld In fld.SubFolders DoEvents FindFile = FindFile + FindFile(tFld.Path, sFile, nDirs, nFiles, _           strOServer, oWrd) Next End If Exit Function

Catch:    FileName = &quot;&quot; If Err.Number = 76 Then MsgBox &quot;This is not a valid path statement&quot; & vbCrLf & _ &quot;The program will end!&quot; End End If  Debug.Print Err.Description fileNumber = FreeFile

'Writes the error description and number to the log file. Open &quot;C:\ChangeTemplate.log&quot; For Append As #fileNumber Write #fileNumber, Err.Description & &quot; &quot; & Err.Number Close #fileNumber Resume Next End Function

Private Sub Command2_Click 'Use this to view the log file. Shell &quot;notepad.exe c:\ChangeTemplate.log&quot;, 1 End Sub In a Standard module, add the following code: Sub ChangeTemplate(SourceFile As String, strServer As String, objWord As Object)

Dim dlgTemplates As Dialog Dim strTemp As String Dim strpath As String Dim objtemplate As String Dim dlgTemplate As Object Dim x As Integer Dim fNumber As Integer Dim objDoc As Object fNumber = FreeFile objWord.Visible = False strTemp = SourceFile

'This function determines if the document is password protected or Read Only. If OpenDocument(objWord, strTemp) = True Then 'This assumes that there is only one document opened. It may have to be adjusted 'to look for additional document being opened. Set objDoc = objWord.Documents(1) 'Dialogs 87 is the Templates and Addins dialog Set dlgTemplates = objWord.Dialogs(87) objtemplate = objWord.Dialogs(87).Template

'parse out the server name from the fullname of the attached template

If Mid(objtemplate, 2, 1) = &quot;:&quot; Or Left(objtemplate, 2) = &quot;\\&quot; Then x = InStr(3, objtemplate, &quot;\&quot;) strTemp = Mid(objtemplate, 3, x - 3) 'if the parse name is the same as the stated server then 'change the attached template to the Normal

If strTemp = strServer Then objDoc.AttachedTemplate = &quot;Normal.dot&quot; 'write to a log file the file name and location Open &quot;C:\ChangeTemplate.log&quot; For Append As #fNumber Write #fNumber, &quot;Document: &quot; & objDoc.fullName & _ &quot;Attached template changed to Normal.dot&quot; Close #fNumber End If      End If     'After the template  is changed, the document is saved and closed. objDoc.Save objDoc.Close Else 'Enter into the log file files that are not opened. Open &quot;C:\ChangeTemplate.log&quot; For Append As #fNumber Write #fNumber, &quot;Document: &quot; & SourceFile & &quot;  not opened! it's      Read Only or Password Protected&quot; Close #fNumber End If

End Sub Function OpenDocument(ByRef objWord As Object, ByVal sDoc As String) As Boolean 'Arguments: ' objWord - a valid Word Application object. ' sDoc   - the complete path and file name of the document to open in Word. ' 'Opens the document specified by the sDoc variable. 'This function returns True if the document is opened and is read/write. 'Else, this function returns False if the document cannot be opened 'or if the document is opened read-only because of the &quot;read-only recommended&quot; setting 'in the document. 'Therefore only if this function returns True if you try to modify the document. 'If False is returned, log the sDoc into a text file and alert the user 'of the list of file(s) that could not be processed by the batch routine. On Error GoTo EH   Dim oDoc As Object Set oDoc = objWord.Documents.Open( _       FileName:=sDoc, _        ReadOnly:=False, _        PasswordDocument:=&quot;?#nonsense@$&quot;, _        WritePasswordDocument:=&quot;?#nonsense@$&quot;) If oDoc.ReadOnly = True Then OpenDocument = False Else OpenDocument = True End If CleanUp: On Error Resume Next Set oDoc = Nothing Exit Function

EH: 'There was an error opening the file. Return False OpenDocument = False Resume CleanUp End Function </li></ol>

back to the top

Method 3: Create a Microsoft Visual Basic for Applications (VBA) macro that loops through all the documents in a folder and changes the old server name with the new server name
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

The following macro loops through all the documents in a folder and changes the old server name with the new server name for the location of the templates. This macro works only if the path for the templates is the same. Sub Test Dim strFilePath As String Dim strPath As String Dim intCounter As Integer Dim strFileName As String Dim OldServer As String Dim NewServer As String Dim objDoc As Document Dim objTemplate As Template Dim dlgTemplate As Dialog

OldServer = &quot;<\\rsnj01\vol1>&quot; NewServer = &quot;<\\rsnyc1p\vol3>&quot; strFilePath = InputBox(&quot;What is the folder location that you want to use?&quot;) If Right(strFilePath, 1) <> &quot;\&quot; Then strFilePath = strFilePath & &quot;\&quot; strFileName = Dir(strFilePath & &quot;*.doc&quot;) Do While strFileName <> &quot;&quot; Set objDoc = Documents.Open(strFilePath & strFileName) Set objTemplate = objDoc.AttachedTemplate Set dlgTemplate = Dialogs(wdDialogToolsTemplates) strPath = dlgTemplate.Template If LCase(Left(strPath, 13)) = LCase(OldServer) Then objDoc.AttachedTemplate = NewServer & Mid(strPath, 14) End If            strFileName = Dir objDoc.Save objDoc.Close Loop Set objDoc = Nothing Set objTemplate = Nothing Set dlgTemplate = Nothing

End Sub

back to the top

Method 4: Create a VBA macro that loops through all the documents in a folder and changes the old server name with the global template (Normal.dot )
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

The following macro loops through all the documents in a folder and changes the old server name with the global template (Normal.dot ).

Note If a document is password protected in anyway, the template will not be changed and the code will fail.

<pre class="fixed_text">Sub Test

Dim strFilePath As String

Dim strPath As String

Dim intCounter As Integer

Dim strFileName As String

Dim OldServer As String

Dim objDoc As Document

Dim objTemplate As Template

Dim dlgTemplate As Dialog

Dim nServer As Integer

'hardcode the name of the old server.

OldServer = &quot;{enter the name of the Old Server}&quot;

nServer = Len(OldServer)

strFilePath = InputBox(&quot;What is the folder location that you want to use?&quot;)

If Right(strFilePath, 1) <> &quot;\&quot; Then strFilePath = strFilePath & &quot;\&quot;

strFileName = Dir(strFilePath & &quot;*.doc&quot;)

Do While strFileName <> &quot;&quot;

Set objDoc = Documents.Open(strFilePath & strFileName)

Set objTemplate = objDoc.AttachedTemplate

Set dlgTemplate = Dialogs(wdDialogToolsTemplates)

strPath = dlgTemplate.Template

If LCase(Left(strPath, nServer)) = LCase(OldServer) Then

objDoc.AttachedTemplate = NormalTemplate

End If

strFileName = Dir

objDoc.Save

objDoc.Close

Loop

Set objDoc = Nothing

Set objTemplate = Nothing

Set dlgTemplate = Nothing

End Sub

back to the top

Method 5: Rename the server, the share, or the folder to the original name
If the server, the share, or the folder that contains the template was moved or renamed, rename the server, the share, or the folder back to the original name.

back to the top

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

Additional query words: slow

Keywords: kbtshoot kbperformance kbprb KB830561

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.