多年來,我一直使用下面的VBA代碼來更改文件夾(包括子文件夾)中所有Word文件的頁腳。VBA - 更改文件夾中的所有Word頁腳 - 不兼容
它工作得很好,但只適用於Word 2003版本!現在,我使用的是Word 2010中,如果我開始的代碼我得到的錯誤:
Run-time error 5111. The command is not available on this platform
Private Sub Image16_Click()
Dim Suchpfad, oPath
Folder = BrowseForFolder("Sélectionnez le dossier où les fichiers doivent être traitées")
If Len(Folder) = 0 Then
MsgBox "Vous n'avez pas sélectionné un dossier!"
Exit Sub
Else
'ChangeFileOpenDirectory Folder
oPath = Folder
'MsgBox oPath
End If
'**** Fußzeilen löschen
Pfad = oPath
With Application.FileSearch
.LookIn = Pfad
.SearchSubFolders = True
.FileType = msoFileTypeWordDocuments
.Execute
For i = 1 To .FoundFiles.Count
strName = .FoundFiles(i)
WordBasic.DisableAutoMacros
Documents.Open FileName:=strName
Dim Abschnitt As Section
For Each Abschnitt In ActiveDocument.Sections
For j = 1 To 3
On Error Resume Next
Abschnitt.Footers(j).Range.Delete
Next j
Next
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Font.Name = "Verdana"
Selection.Font.Size = 7
Selection.TypeText Text:="First Line of Footer"
Selection.TypeParagraph
Selection.Font.Size = 6
Selection.TypeText Text:="Second Line of Footer"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Save
ActiveDocument.Close
Next
End With
MsgBox "Operation done in " & Pfad & " !!!"
End Sub
我無法弄清楚這個問題,我希望有人有一個解決方案。
Application.FileSearch 2007年後 –
你好@ Dy.Lee不協助,感謝相關信息。你知道是否存在Word 2007及更高版本的等價物? – achillix