用于编辑标题的 WORD 2010 宏页脚 [英] WORD 2010 Macro for Editing Headers & Footers
问题描述
我只有基本的 VBA 经验,我之前的宏经验主要是使用 WORD 2003.录制宏用于获取 GoToFooter(或编辑页脚)菜单命令并允许后续编辑.在 WORD 2010 中,此(以及许多其他)命令不会记录"到宏(但在记录模式下,我确实进入了编辑页脚"功能).
I have only basic VBA experince and my prior Macro experence was primarily with WORD 2003. Recording Macros used to take GoToFooter (or Edit Footer) Menu Commands and allow subsequent editing. In WORD 2010, this (and many other) commands do not "record" to the Macro (yet when in Record mode, I do get into Edit Footer function).
对各种 VBS 选项的研究显示了在宏中创建页脚和更改全局页脚设置的几种方法.但是,如果我只是想在页脚中修改公司名称(例如),我无法在宏子例程中执行此操作.
A research of various VBS options shows several ways to create Footers and to make global Footer setting changes within Macro. However If I simply want to Revise the Company name within the Footer (for example), I can find no way to do this within a Macro subroutine.
这个子例程是我会从主宏调用的子例程,它正在单步执行文件夹(和子文件夹)中的每个文件.我有主要的宏功能.
This subroutine is one that I would call from the Main Macro that is stepping through each file in a Folder (& subfolders). I have the main Macro functioning.
WORD 2010 Macro-VBA 是否排除了简单的编辑页脚功能?
Does WORD 2010 Macro-VBA preclude simple Edit-Footer function?
提前致谢
所以,感谢 Issun,这是我的解决方案:
So, thanks to Issun, here is my solution:
`
Sub Sub_FTR_0()
'
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
For i = 1 To ActiveDocument.Sections.Count
'REM: INSERT Code from RECORD MACRO recorded when editing one Footer correctly
Selection. [[xxx]], etc.
If i = ActiveDocument.Sections.Count Then GoTo Line1
ActiveDocument.ActiveWindow.ActivePane.View.NextHeaderFooter
Line1:
Next
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
`
推荐答案
这是一种可以通过 VBA 访问页眉/页脚的方法.如您所见,实现如此简单的事情的语法相当复杂 :p
Here is a way you can access the headers/footers via VBA. As you can see, it's rather complicated syntax to get to something so simple :p there
Sub EditHeadersAndFooters()
Dim i As Long
For i = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Text = "Foo"
.Footers(wdHeaderFooterPrimary).Range.Text = "Bar"
End With
Next
End Sub
这是有关如何更改文件夹中每个文件的标题的示例代码的链接.它采用了不同的方法,我从未尝试过,但供您参考:http://www.vbaexpress.com/kb/getarticle.php?kb_id=45
Here is a link to example code on how to change the headers in every file in a folder. It takes a different approach and I have never tried it, but for your reference: http://www.vbaexpress.com/kb/getarticle.php?kb_id=45
这篇关于用于编辑标题的 WORD 2010 宏页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!