我想检查Excel工作表上的页眉和页脚,并用另一个字符串替换给定字符串的所有出现次数。如何使用vba完成?
答案 0 :(得分:3)
您需要使用Sheet.PageSetup
属性。我假设你正在寻找中心页眉和页脚。以下内容适合您
Sub LoopThroughPageSetup()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If sh.PageSetup.CenterHeader = "hello" Then 'change to whatever you want
sh.PageSetup.CenterHeader = "hi"
End If
If sh.PageSetup.CenterFooter = "hi" Then
sh.PageSetup.CenterFooter = "hello"
End If
Next sh
End Sub