VBA;多个页脚和页眉对齐方式,如何对齐左居中和右页脚?
VBA; Multiple footer and header allignment, How can I allgine left Center and right footer?
我知道有这样的代码:
With ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range
.Text = myFooterValue1
.ParagraphFormat.Alignment = wdAlignPageNumberLeft
.Font.Size = 10 'size 10 font
End With
但我想添加,左(公司名称)右(日期)和中间页码。
你可以用 TabStops 做到这一点。
您需要计算出页面的宽度(减去边距),添加居中和右侧的 TabStop 并使用制表符分隔您的值。
Sub insertFooters()
Dim pageWidth As Double, section As section
For Each section In ActiveDocument.Sections
With section.PageSetup
pageWidth = (.pageWidth) - .LeftMargin - .RightMargin
End With
With section.Footers(wdHeaderFooterPrimary).Range
.Text = "Left" & vbTab & "Center" & vbTab & "Right"
With .ParagraphFormat
.TabStops.ClearAll
.TabStops.Add pageWidth / 2, Alignment:=WdAlignmentTabAlignment.wdCenter
.TabStops.Add pageWidth, Alignment:=WdAlignmentTabAlignment.wdRight
End With
.Font.Size = 10
End With
Next
End Sub
我知道有这样的代码:
With ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range
.Text = myFooterValue1
.ParagraphFormat.Alignment = wdAlignPageNumberLeft
.Font.Size = 10 'size 10 font
End With
但我想添加,左(公司名称)右(日期)和中间页码。
你可以用 TabStops 做到这一点。
您需要计算出页面的宽度(减去边距),添加居中和右侧的 TabStop 并使用制表符分隔您的值。
Sub insertFooters()
Dim pageWidth As Double, section As section
For Each section In ActiveDocument.Sections
With section.PageSetup
pageWidth = (.pageWidth) - .LeftMargin - .RightMargin
End With
With section.Footers(wdHeaderFooterPrimary).Range
.Text = "Left" & vbTab & "Center" & vbTab & "Right"
With .ParagraphFormat
.TabStops.ClearAll
.TabStops.Add pageWidth / 2, Alignment:=WdAlignmentTabAlignment.wdCenter
.TabStops.Add pageWidth, Alignment:=WdAlignmentTabAlignment.wdRight
End With
.Font.Size = 10
End With
Next
End Sub