如何批量去掉word页眉页脚

www.tzvx.com 2021-01-11生活日记人已围观

简介对于单个word文件,删除页眉页脚,相对简单,但是对于多个或者上千个文档的时候,我们需要宏运行来辅助。 步骤一、开启宏设置 office2007设置:开发工具-宏安全性-宏设置-启用所有宏...

对于单个word文件,删除页眉页脚,相对简单,但是对于多个或者上千个文档的时候,我们需要宏运行来辅助。



步骤一、开启宏设置
office2007设置:开发工具-宏安全性-宏设置-启用所有宏
office2013设置:左上角文件-选项-信任中心-信任中心设置-启用所有宏

步骤二、复制以下代码,新建宏

Sub 批量删除文件夹里面所有Word文档的页眉页脚()
Dim Fdlg As FileDialog, Fl
Dim Fso, Fld, Fln, Wk
Set Fdlg = Application.FileDialog(msoFileDialogFolderPicker)
With Fdlg
.Title = "选择要处理目标文件夹" & "——(删除里面所有Word文档的页眉页脚)"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Fld = Fso.GetFolder(MyPath)
Set Fln = Fld.Files
For Each Wk In Fln
Set myDoc = Documents.Open(FileName:=Fld & "" & Wk.Name)
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 Sub

保存之后,打开宏,运行刚刚新建的宏,然后选择需要删除页眉页脚的文件夹,批量删除页脚页眉开始。

Tags:

热点文章