本文介绍了替换Excel文件的页眉和页脚中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查Excel工作表上的页眉和页脚,并用另一个字符串替换给定字符串的所有出现次数.如何使用vba完成此操作?
I want to check the header and footer on a Excel sheet, and replace all the ocurrences of a given string by another string. How can this be done using vba?
推荐答案
您将需要使用 Sheet.PageSetup
属性.我假设您正在寻找中心页眉和页脚.以下内容将为您服务
You will need to use to use Sheet.PageSetup
property. I am assuming you are looking for center header and footer. The following will work for you
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
这篇关于替换Excel文件的页眉和页脚中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!