我正在尝试创建一个表格并将文本垂直居中。当我创建表格时,我用文本填充单元格并应用对齐:
Dim pg As Page
Dim tbl As Shape
Set pg = ActiveDocument.ActiveView.ActivePage
Set tbl = pg.Shapes.AddTable(1, 1, InchesToPoints(3), InchesToPoints(5), InchesToPoints(2), InchesToPoints(1))
With tbl.Table.Rows(1).Cells(1)
.TextRange.Text = "Hello, World!"
.VerticalTextAlignment = pbVerticalTextAlignmentCenter
End With
但是,文本没有垂直对齐。当我查看“格式表”下的“单元格属性”选项卡时,我看到它已经设置为“中间”垂直对齐,但只有在我点击“确定”时才会应用此选项(如果我点击取消,则没有任何更改)。
如果在应用对齐之前或之后更改文本,则无关紧要。任何人都对为什么会这样做有任何想法?
答案 0 :(得分:0)
#If Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds as Long) 'For 32 Bit Systems
#End If
Sub Centralize(oCellRange As CellRange)
oCellRange.Select
Sleep 500
Application.ActiveDocument.ActiveWindow.Activate
SendKeys "%JL1", True
End Sub
Sub Test()
Dim oCellRange As CellRange
Set oCellRange = Application.ActiveDocument.Pages(1).Shapes(1).Table.Cells(1, 1, 2, 2)
Call Centralize(oCellRange)
End Sub