文档带有附加模板需要很长的时间,若要在 Word 2002 和 Word 2003 中打开

文章翻译 文章翻译
文章编号: 830561 - 查看本文应用于的产品
展开全部 | 关闭全部

本文内容

症状

当您打开 Microsoft Word 文档 (*.doc) 文件中,该文档可能需要更长时间,则应打开。例如,文档可能需要 5 到 10 分钟的时间才能打开。

原因

如果文档包含一个模板,可能会出现此症状附加或链接,并满足下列条件之一为真:
  • 其附属的模板,其文件夹中,或者其共享缺少。
  • 该附加的模板已被移动。
  • 该附加的模板已被重命名。
缺少 Word 模板时,Windows XP 将尝试查找缺少模板多次。定位丢失的模板的过程可能会导致长比预期的要打开一个 Word 文档。

它需要较长时间才能打开的文档,当您连接到与您从网络断开连接的网络。

解决方案

工作解决这样的问题在一台计算机上安装 Windows XP,请使用之一根据您的具体情况的下列方法:

方法 1: 从新位置加载模板

在 Microsoft Word 中打开的文档。等待,直到在文档处于打开状态。之后此文档已打开,将该模板附加从新的位置。或者,更改共用模板 Normal.dot 模板。若要将附加模板,请按照下列步骤操作:
  1. 在上 工具 菜单上,单击 模板和外接程序.
  2. 在中 模板和加载项 对话框中,单击 附加.
  3. 在中 应用模板 对话框中选择该模板,然后单击 打开.
  4. 在中 模板和加载项 对话框中,单击 确定.

返回页首

方法 2: 使用自定义Visual Basic 应用程序附加的模板更改为全局模板(Normal.dot) 打开新文档时

Microsoft 提供的编程示例仅用于说明,没有任何明示或暗示的担保。这包括但不限于对适销性或对特定用途的适用性的暗示保证。本文假定您熟悉所演示的编程语言和用于创建和调试过程的工具。Microsoft 的支持工程师可以帮助解释某个特定过程的功能。但是,他们不会修改这些示例以提供额外的功能或构建过程以满足您的特定要求。

使用自定义的解决方案来更改连接共用模板 (Normal.dot),当一个新的文档模板打开。

注意请确保该宏的安全性设为中或低。

若要在 Microsoft Visual Basic 6 中创建自定义的解决方案,请按照这些步骤如下:
  1. 打开一个新的 Standard.exe 项目。
  2. 用户窗体上添加以下组件:
    • 一个列表框
    • 两个文本框
    • 四个命令按钮
    • 两个标签
  3. 设置 Microsoft 脚本运行时对的引用(Scrun.dll)。
  4. 复制并粘贴下面的代码在用户窗体中:
    Option Explicit
    
    Private Const BIF_RETURNONLYFSDIRS = 1
    Private Const BIF_DONTGOBELOWDOMAIN = 2
    Private Const MAX_PATH = 260
    Private Declare Function SHBrowseForFolder Lib "shell32" _
       (lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" _
       (ByVal pidList As Long, _
       ByVal lpBuffer As String) As Long
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
       (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 = "This is the title"
       With tBrowseInfo
          .hWndOwner = Me.hWnd
          .lpszTitle = lstrcat(szTitle, "")
          .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 = "This is the title"
        With tBrowseInfo
           .hWndOwner = Me.hWnd
           .lpszTitle = lstrcat(szTitle, "")
           .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("Word.Application")
       strServer = txtOldServer.Text
       nTime = Time()
       fileNumber = FreeFile
           
       List1.Clear
           
       Open "C:\ChangeTemplate.log" For Append As #fileNumber
       Write #fileNumber, "Start:" & " " & 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 = "*.doc"
       
      MousePointer = vbHourglass
    
     'The label shows the current subfolder being searched.
      Label1.Caption = "Searching Folder: " & vbCrLf & UCase(sDir) & "..."
      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 "C:\ChangeTemplate.log" For Append As #fileNumber
      Write #fileNumber, "Stop:" & " " & ntime2 & " " & _
         "Time to Complete the Changes: " & _
         Format(ntime2 - nTime, "nn:ss") & vbCrLf _
         & Str(nFiles) & " files found in" & Str(nDirs) & _
         " directories"
      Close #fileNumber
      ' Debug.Print "Stop:" & " " & ntime2
      Label1.Caption = "Done"
      If Label1.Caption = "Done" Then Command2.Enabled = True
         MsgBox "Done"
         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 & "\" & FileName
          '==
            
          ChangeTemplate strFileName, strOServer, oWrd
          FileName = Dir()  ' Get next file
          DoEvents
       Wend
       Label1 = "Searching " & vbCrLf & fld.Path & "..."
       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 = ""
        
       If Err.Number = 76 Then
          MsgBox "This is not a valid path statement" & vbCrLf & _
             "The program will end!"
          End
       End If
       Debug.Print Err.Description
       fileNumber = FreeFile
    
       'Writes the error description and number to the log file.
       Open "C:\ChangeTemplate.log" For Append As #fileNumber
       Write #fileNumber, Err.Description & " " & Err.Number
       Close #fileNumber
       Resume Next
    End Function
    
    Private Sub Command2_Click()
        'Use this to view the log file.
        Shell "notepad.exe c:\ChangeTemplate.log", 1
    End Sub
    
    在标准模块中,将添加下面的代码:
    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) = ":" Or Left(objtemplate, 2) = "\\" Then
              x = InStr(3, objtemplate, "\")
              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 = "Normal.dot"
                 'write to a log file the file name and location
                 Open "C:\ChangeTemplate.log" For Append As #fNumber
                 Write #fNumber, "Document: " & objDoc.fullName & _
                 "Attached template changed to Normal.dot"
                 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 "C:\ChangeTemplate.log" For Append As #fNumber
          Write #fNumber, "Document:  " & SourceFile & "  not opened! it's 
          Read Only or Password Protected"
          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 "read-only recommended" 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:="?#nonsense@$", _
            WritePasswordDocument:="?#nonsense@$")
        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
    

返回页首

方法 3: 创建Microsoft Visual Basic for Applications 循环遍历所有的加载宏在文件夹中的文档,并更改旧与新服务器的服务器名称名称

Microsoft 提供的编程示例仅用于说明,没有任何明示或暗示的担保。这包括但不限于对适销性或对特定用途的适用性的暗示保证。本文假定您熟悉所演示的编程语言和用于创建和调试过程的工具。Microsoft 的支持工程师可以帮助解释某个特定过程的功能。但是,他们不会修改这些示例以提供额外的功能或构建过程以满足您的特定要求。

下面的宏将遍历所有文档在文件夹和更改旧服务器名称与新服务器名称模板的位置。此宏的工作方式仅在模板的路径是相同的。
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 = "<\\rsnj01\vol1>" 
   NewServer = "<\\rsnyc1p\vol3>" 
   strFilePath = InputBox("What is the folder location that you want to use?") 
   If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\" 
   strFileName = Dir(strFilePath & "*.doc")  
      Do While strFileName <> ""    
         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

返回页首

方法 4: 创建 VBA 宏,在循环遍历文件夹中的所有文档,并更改共用模板 (Normal.dot) 与旧服务器名称

Microsoft 提供的编程示例仅用于说明,没有任何明示或暗示的担保。这包括但不限于对适销性或对特定用途的适用性的暗示保证。本文假定您熟悉所演示的编程语言和用于创建和调试过程的工具。Microsoft 的支持工程师可以帮助解释某个特定过程的功能。但是,他们不会修改这些示例以提供额外的功能或构建过程以满足您的特定要求。

下面的宏循环遍历所有在文件夹中的文档,并更改共用模板与旧服务器名称(Normal.dot)。

注意如果文档有密码保护,则该模板将不能更改,该代码将失败。
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 = "{enter the name of the Old Server}"

    nServer = Len(OldServer)

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

 

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

     strFileName = Dir(strFilePath & "*.doc")

     Do While strFileName <> ""

     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


返回到顶部

方法 5: 为原始名称重命名服务器、 共享或文件夹

如果服务器、 共享或包含该模板的文件夹已移动或重命名,重命名服务器、 共享或文件夹返回到原始名称。

如果旧服务器不再存在,您可以用旧服务器名称创建 DNS 条目。旧服务器名称 DNS 条目之后,可以创建模板路径中所列的相同的文件夹结构并将该模板复制到该文件夹。

状态

Microsoft 已经确认这是在"适用于"一节中列出的 Microsoft 产品中的问题。

属性

文章编号: 830561 - 最后修改: 2013年5月20日 - 修订: 1.0
这篇文章中的信息适用于:
  • Microsoft Word 2002 标准版?当用于
    • Microsoft Windows XP Home Edition
    • Microsoft Windows XP Professional Edition
关键字:?
kbperformance kbtshoot kbprb kbmt KB830561 KbMtzh
机器翻译
重要说明:本文是由 Microsoft 机器翻译软件进行的翻译并可能由 Microsoft 社区通过社区翻译机构(CTF)技术进行后期编辑,或可能是由人工进行的翻译。Microsoft 同时向您提供机器翻译、人工翻译及社区后期编辑的文章,以便对我们知识库中的所有文章以多种语言提供访问。翻译的文章可能存在词汇、句法和/或语法方面的错误。Microsoft 对由于内容的误译或客户对内容的使用所导致的任何不准确、错误或损失不承担责任。
点击这里察看该文章的英文版: 830561
Microsoft和/或其各供应商对于为任何目的而在本服务器上发布的文件及有关图形所含信息的适用性,不作任何声明。 所有该等文件及有关图形均"依样"提供,而不带任何性质的保证。Microsoft和/或其各供应商特此声明,对所有与该等信息有关的保证和条件不负任何责任,该等保证和条件包括关于适销性、符合特定用途、所有权和非侵权的所有默示保证和条件。在任何情况下,在由于使用或运行本服务器上的信息所引起的或与该等使用或运行有关的诉讼中,Microsoft和/或其各供应商就因丧失使用、数据或利润所导致的任何特别的、间接的、衍生性的损害或任何因使用而丧失所导致的之损害、数据或利润不负任何责任。

提供反馈

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com