好文分享

【WORD VBA】自動插入底稿頁尾

Sub 自動插入底稿頁尾()

Dim mytable As table
With ActiveDocument
Set mytable = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).range, 2, 4)
End With
With mytable
.Cell(1, 1).range.Text = “XX”
.Cell(1, 1).range.font.Size = 12
.Cell(1, 1).range.font.Name = “標楷體”
With mytable.Cell(1, 1).range
.ParagraphFormat.Alignment = Word.WdHorizontalLineAlignment.wdHorizontalLineAlignCenter ‘水平置中
End With

.Cell(1, 2).range.Text = “XX”
.Cell(1, 2).range.font.Size = 12
.Cell(1, 2).range.font.Name = “標楷體”
With mytable.Cell(1, 2).range
.ParagraphFormat.Alignment = Word.WdHorizontalLineAlignment.wdHorizontalLineAlignCenter ‘水平置中
End With

.Cell(1, 4).range.Text = “XX”
.Cell(1, 4).range.font.Size = 12
.Cell(1, 4).range.font.Name = “標楷體”
With mytable.Cell(1, 4).range
.ParagraphFormat.Alignment = Word.WdHorizontalLineAlignment.wdHorizontalLineAlignCenter ‘水平置中
End With

.Cell(2, 4).range.Text = “XX(/)”
.Cell(2, 4).range.font.Size = 12
.Cell(2, 4).range.font.Name = “times new romans”
With mytable.Cell(2, 4).range
.ParagraphFormat.Alignment = Word.WdHorizontalLineAlignment.wdHorizontalLineAlignCenter ‘水平置中
End With

Set mytable = ActiveDocument.Tables(1)
mytable.Borders.InsideLineStyle = wdLineStyleDot
mytable.Borders.InsideLineWidth = wdLineWidth075pt ‘將內部框線設定為0.75pt。
mytable.Borders.OutsideLineStyle = wdLineStyleSingle
mytable.Borders.OutsideLineWidth = wdLineWidth150pt ‘將外部框線設定為1.50pt。
mytable.Shading.BackgroundPatternColor = wdColorWhite ‘將表格網底設定為白色。

End With

ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add

End Sub