修改如下:
Sub 删除页眉页脚()
Dim myRange As Range
On Error Resume Next
For Each oSec In ThisDocument.Sections '文档的节中循环
Set myRange = oSec.Headers(wdHeaderFooterPrimary).Range
myRange.Delete '删除页眉中的内容
myRange.ParagraphFormat.Borders(wdBorderBottom).LineStyle = wdLineStyleNone '段落下边框线
Set myRange = oSec.Footers(wdHeaderFooterPrimary).Range
myRange.Delete '删除页脚中的内容
Next
End Sub