批量删除Word文档页眉或页脚的方法
绝对可用批量删除word页眉页脚方法
1、首先创建2个宏
在word里面,点工具--宏--录制新宏--把名字‘Macro1’改为‘批量删除页脚’和‘Macro2’改为‘批量删除页脚’--点确定
2、然后点工具--宏--停止录制
3、点工具--宏--宏
4、选择‘批量删除页脚’——点编辑
将下面代码黏贴到出现的页面
Sub批量删除页脚()
Application.ScreenUpdating = False
Dim MyPath As String, i As Integer, myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择要处理目标文件夹" & "——(删除里面所有Word文档的页眉页脚)"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn = MyPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(FileName:=.FoundFiles(i))
' B可以替换的宏
' 以下是处理格式所录制的宏,可根据所需录制
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
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.WholeStory
With Selection.ParagraphFormat
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth075pt
.DefaultBorderColor = wdColorAutomatic
End With
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberRight, FirstPage:=True
' 以上可以换成是你自己录制的宏
' C公共部分的代码
Application.DisplayAlerts = False '强制执行“是”
'ActiveDocument.Saved = True'强制执行“否”
ActiveDocument.Close '退出
Next
End If
End With
Application.Screen
Updating = True
MsgBox "所选Word文档的页眉页脚已删除", 64, "☆★批量处理完毕★☆"
End Sub
同上1-4步骤创建批量删除页眉,代码如下
Sub 批量删除页眉()
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 '段落下边框线
Set myRange = oSec.Footers(wdHeaderFooterPrimary).Range
myRange.Delete '删除页脚中的内容
Next
oDoc.Close True
Next
End If
End With
End Sub
5、到此宏创建成功
然后开始批量删除页眉页脚
htmlborder6、点工具--宏--宏
7、选中批量删除,点运行
8、选中你要批量处理的文档即可

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。