如何使用Word中的宏创建的表格中的文本
问题描述:
我有一个创建具有2列的表格的宏。我想把文本居中。如何使用Word中的宏创建的表格中的文本
因为我在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
答
如果要将文本居中对齐,则需要引用任何Range对象。因此,尝试用这个选项
对于整个表
oTable.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
对于任何单个列(这里,为第一和第二列)
oTable.Columns(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
oTable.Columns(2).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
+0
您好Kaz - FYI我通过添加oWordDocument.Range.ParagraphFormat.Alignment = 1在我的代码中的其他地方通过试验和错误managaed得到这个工作。 – user2791146
答
这条线组对准到中心对于特定表格中的所有单元格:
cDoc.Tables(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
如果记录与否有什么区别。 MacroRecorder是你获得这个财产的第一个也是最好的解决方案。所以,你应该使用它。然而,你需要的可能是这样的:'Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter' –
谢谢KazJaw - 我做了这个,但得到了一个错误。它指出wdAlignParagraphCenter没有定义。所以我试图添加一行,说const wdAlignParagraphCenter = 1,但仍然没有运气 – user2791146
你提到你使用'特定的工具以外的微软word'这可能是一个问题......这是什么工具?你目前的代码是什么? –