在页脚或页眉中添加2个表

时间:2020-06-03 07:12:37

标签: vba ms-word

  1. 我正在尝试将表格添加到页脚中。但是,一旦我创建了第二张表,

6028错误:无法删除范围。

如果我交换表,它将创建一个表,并在其中创建另一个表。这不是我的目标。要创建两个分开的表,允许它们彼此重叠。

  1. 输入尺寸后,分别添加RelativeHorizontalPositionPageset RowsHeight.Rows.Allowoverlap = True,它会给我另一个

错误5149尺寸必须在0厘米至55.87厘米之间。

我知道我做错了,只是想不出什么。这就是我最终想要得到的

enter image description here

将提供任何帮助。

Set oHF = ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage)


Set aTable2 = oHF.Range.Tables.Add(Range:= _
oHF.Range, Numrows:=1, NumColumns:= _
3, DefaultTableBehavior:=wdWord8TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed)

With aTable2

'.Rows.AllowOverlap = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Rows.SetHeight RowHeight:=CentimetersToPoints(0.5), _
HeightRule:=wdRowHeightAtLeast
.Rows.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Rows.RelativeVerticalPosition = wdRelativeVerticalPositionPage

.Rows.HorizontalPosition = CentimetersToPoints(2)
.Rows.VerticalPosition = CentimetersToPoints(25.25)
End With

Set aTable = oHF.Range.Tables.Add(Range:= _
oHF.Range, Numrows:=8, NumColumns:= _
1, DefaultTableBehavior:=wdWord8TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed)
With aTable

'.Rows.AllowOverlap = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Rows.SetHeight RowHeight:=CentimetersToPoints(0.5), _
HeightRule:=wdRowHeightAtLeast

.Rows.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Rows.RelativeVerticalPosition = wdRelativeVerticalPositionPage

.Rows.HorizontalPosition = CentimetersToPoints(2)
.Rows.VerticalPosition = CentimetersToPoints(25.25)

1 个答案:

答案 0 :(得分:0)

基本上:

Sub Demo()
Dim HdFt As HeaderFooter, Tbl As Table
With ActiveDocument
  Set HdFt = .Sections(1).Footers(wdHeaderFooterFirstPage)
  Set Tbl = .Tables.Add(Range:=HdFt.Range.Characters.Last, Numrows:=1, NumColumns:=3, _
    DefaultTableBehavior:=wdWord8TableBehavior, AutoFitBehavior:=wdAutoFitFixed)

  'Process 1st table
  With Tbl
    'including:
    .Rows.WrapAroundText = True
  End With

  Set Tbl = .Tables.Add(Range:=HdFt.Range.Characters.Last, Numrows:=8, NumColumns:=1, _
    DefaultTableBehavior:=wdWord8TableBehavior, AutoFitBehavior:=wdAutoFitFixed)

  'Process 2nd table
  With Tbl

  End With
End With
End Sub