學習啦 > 學習電腦 > 工具軟件 > 辦公軟件學習 > word排版教程 > Word常見問題 > 怎么在word中批量刪除頁眉和頁腳

怎么在word中批量刪除頁眉和頁腳

時間: 張偉670 分享

怎么在word中批量刪除頁眉和頁腳

  在日常工作中,我們有時會碰到一大堆文件需要批量刪除頁眉與頁腳,如果一個個打開文件手工刪除的話,會很耗時間精力,下面小編就教你怎么在word中批量刪除頁眉和頁腳,希望對你有幫助!

  word中批量刪除頁眉和頁腳的步驟

  首先,我先制作一個測試文件夾,里面包含幾個word文檔,都有頁眉--百度經(jīng)驗這四個字,當然其他的文字也行,只是一個測試;


word中批量刪除頁眉和頁腳的步驟圖1

  下面我們需要打開宏,03版的宏不需要去開啟開發(fā)工具,只需要點擊菜單欄中的工具-宏-宏;


word中批量刪除頁眉和頁腳的步驟圖2

  進入宏對話框,我們可以在宏名隨便輸入英文字母,在右側(cè)點擊一下創(chuàng)建;


word中批量刪除頁眉和頁腳的步驟圖3

  接著,進入了宏代碼編寫框,將下面代碼復(fù)制進來:

  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可以替換的宏

  ' 以下是處理格式所錄制的宏,可根據(jù)所需錄制

  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 '強制執(zhí)行“是”

  'ActiveDocument.Saved = True'強制執(zhí)行“否”

  ActiveDocument.Close '退出

  Next

  End If

  End With

  Application.ScreenUpdating = True

  MsgBox "所選Word文檔的頁眉頁腳已刪除!!!", 64, "☆★處理完畢★☆"

  End Sub


word中批量刪除頁眉和頁腳的步驟圖4

  現(xiàn)在,我們關(guān)閉窗口,重新回到word界面,按下宏快捷鍵,Alt+F8,看到剛才的宏名,點擊運行;


word中批量刪除頁眉和頁腳的步驟圖5

  接著軟件會讓我們選擇要批量處理的文件夾,選中之,然后稍等片刻,即會彈出--所選Word文檔的頁眉頁腳已刪除。


word中批量刪除頁眉和頁腳的步驟圖6

  >>>下一頁更多精彩“刪除word中頁眉和頁腳方法”

417028