1

我有一个宏,它创建一个有 2 列的表。我想使文本居中。

我需要知道执行此操作的实际功能/方法(即未记录),因为我正在 Microsoft Word 之外的特定工具中编辑复杂的宏。

Function TableStyleApply(oTable)
  Const wdLineWidth050pt = 4
  Const wdLineStyleSingle = 1
  Const wdBorderTop = -1
  Const wdBorderLeft = -2
  Const wdBorderBottom = -3
  Const wdBorderRight = -4
  Const wdBorderHorizontal = -5
  Const wdBorderVertical = -6
  Const wdAlignParagraphCenter = 100

  oTable.Borders(wdBorderTop ).LineStyle = wdLineStyleSingle
  oTable.Borders(wdBorderLeft ).LineStyle = wdLineStyleSingle
  oTable.Borders(wdBorderBottom ).LineStyle = wdLineStyleSingle
  oTable.Borders(wdBorderRight ).LineStyle = wdLineStyleSingle
  oTable.Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle
  oTable.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle

  oTable.Rows(1).Range.Font.Bold = True
  oTable.Rows(1).Shading.BackgroundPatternColor = 15132390
  oTable.Rows.LeftIndent = 43
  oTable.Columns(1).SetWidth 280, 2
  oTable.Columns(2).SetWidth 157, 2

  oTable.Columns.ParagraphFormat.Alignment = wdAlignParagraphCenter

End Function
4

2 回答 2

4

如果要将文本居中对齐,则需要引用任何 Range 对象。所以,试试这个选项

对于整张桌子

oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter

对于任何单列(此处为第一列和第二列)

oTable.Columns(1).Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

oTable.Columns(2).Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
于 2013-10-21T13:04:17.100 回答
0

此行将特定表格中所有单元格的对齐设置为居中:

cDoc.Tables(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
于 2017-01-31T14:38:00.947 回答