以下是引用acer_peri在2007-12-24 20:25:36的发言: 请各位帮助偶一下,如何批量去除一个文件夹下所有Word文件的页眉和页脚?用VBA也可以。谢谢。 请参考: '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2007-12-25 18:34:02 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0291^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Option Explicit
Sub Example() '此代码功能为列出指定文件夹中所有选取的WORD文件全路径名 Dim myDialog As FileDialog, oDoc As Document, oSec As Section Dim oFile As Variant, myRange As Range On Error Resume Next '定义一个文件夹选取对话框 Set myDialog = Application.FileDialog(msoFileDialogFilePicker) With myDialog .Filters.Clear '清除所有文件筛选器中的项目 .Filters.Add "所有 WORD 文件", "*.doc", 1 '增加筛选器的项目为所有WORD文件 .AllowMultiSelect = True '允许多项选择 If .Show = -1 Then '确定 For Each oFile In .SelectedItems '在所有选取项目中循环 Set oDoc = Word.Documents.Open(FileName:=oFile, Visible:=False) For Each oSec In oDoc.Sections '文档的节中循环 Set myRange = oSec.Headers(wdHeaderFooterPrimary).Range myRange.Delete '删除页眉中的内容 myRange.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '段落下边框线 Next oDoc.Close True Next End If End With End Sub '----------------------
|