含有附加範本的文件會花很長的時間,若要開啟在 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: 建立(VBA) 巨集,瀏覽所有的 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: 建立循環的資料夾中的所有文件,並變更舊的伺服器名稱與共用範本 (Normal.dot) 的 VBA 巨集

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 Standard Edition?應用於:
    • Microsoft Windows XP Home Edition (家用版)
    • Microsoft Windows XP Professional
關鍵字:?
kbperformance kbtshoot kbprb kbmt KB830561 KbMtzh
機器翻譯
請注意--重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,且可能由 Microsoft Community 利用 Community Translation Framework技術或人工進行事後編修。翻譯過程並無專業譯者參與。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