使用VBA创建Word文档底部并右对齐

3

我正在使用VBA创建一个Word文档,我只需要编辑页眉和页脚。当我运行下面的VBA时,页脚处于居中位置...如何将其右对齐?谢谢!

With ActiveDocument.Sections(1)
.Headers(wdHeaderFooterPrimary).range.Text = DocName
.Headers(wdHeaderFooterPrimary).range.Font.Name = "Arial"
.Headers(wdHeaderFooterPrimary).range.Font.size = 9
.Footers(wdHeaderFooterPrimary).range.Text = Format(Date, "Long Date") 
.Footers(wdHeaderFooterPrimary).range.Font.Name = "Arial"
.Footers(wdHeaderFooterPrimary).range.Font.size = 9
End With
1个回答

3

有多种方式来格式化页脚的内容...

  1. 最“正确”的方法是更改页脚样式的定义。这将包括代码中直接应用的字体格式。

例如:

With ActiveDocument.Styles("Footer")
  .Font.Name = "Arial"
  .Font.Size = 9
  .ParagraphFormat.Alignment = wdAlignParagraphRight
End With
  1. 如果要直接应用格式,可以直接应用右对齐:

以问题中的代码为例:

.Footers(wdHeaderFooterPrimary).range.ParagraphFormat.Alignment = wdAlignParagraphRight
  1. 默认页脚样式定义了三个制表位:左对齐、居中和右对齐。这允许内容在页面上对齐。为了使用它,将段落对齐方式从(1)或(2)中省略,并在写入页脚的字符串开头放置两个TAB字符 (vbTab):

以问题中的代码为例:

.Footers(wdHeaderFooterPrimary).range.Text = vbTab & vbTab & Format(Date, "Long Date") 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接