我有一个带有现有页眉和页脚的 Word Doc。在页脚内部有一个表格,其中包含一些单元格中的信息。我想知道在页脚表中编辑和添加更多内容的 Excel VBA 代码(例如更新单元格的信息或在空单元格中添加信息)。我面临的最大问题是我不知道如何引用页脚表中的单元格位置。
我正在使用 Office 2013 并尝试了以下方法:
- wDoc.Sections(1).Footers(wdHeaderFooterPrimary)
- wDoc.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
- Set rngFooter = wDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
With rngFooter
.ParagraphFormat.Alignment = 1
.Text = "Some text"
.Move Unit:=wdColumn, Count:=1
.Text = "More Text at center: hyperlink"
.Move Unit:=wdColumn, Count:=1
.Text = "Page 1 of 1"
.Move Unit:=wdRow, Count:=1
.Text = "New Text in empty cell"
With .Font
.Size = 9
.Name = "Arial Narrow"
End With
End With
- wDoc.Sections(1).Footers.Select
在第三种方法的情况下,我得到以下信息:
第三种方法代码的页脚结果

