有許多人剛接觸WORD的新手,常常會遇到的問題就是怎樣刪除頁眉頁腳,當然一個Word里面刪除頁眉頁腳不難,但有幾百多個Word里面都有頁眉頁腳要你刪除,那就難到不少人了,下面將針對這一問題,看看我是怎么利用宏批量刪除多個Word頁眉頁腳,我獻丑了。
1、假如我手上有500個word文檔需要刪除頁眉頁腳

2、先把需要刪除頁眉頁腳的500個word文檔放在一個文件夾下,然后打開其中一個文檔


3、在打開的文檔中,選擇在“工具”菜單中選擇“宏”--“宏”

4、隨后彈出“宏”對話框,在宏名中輸入"Application",最后點擊"創建"按鈕

5、隨后彈出“Microsoft visual basic”設計,在編輯處輸入如下代碼
Sub 批量刪除Word頁眉頁腳()
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.ScreenUpdating = True
MsgBox "所選Word文檔的頁眉頁腳已刪除!!!", 64, "☆★批量處理完畢★☆"
End Sub
Sub ConvertEqns()
'
' ConvertEqns Macro
' 宏在 2014-6-25 由 USER 創建
'
End Sub

6、輸入代碼后,關閉窗口返回文檔,重新選擇在“工具”菜單中選擇“宏”--“宏”,在彈出的宏名中選擇"批量刪除Word頁眉頁腳",最后點擊“運行”---確認即可快速地刪除500個Word頁眉頁腳


相關推薦:
新聞熱點
疑難解答