1

我正在尝试创建一个表格并将文本垂直居中。创建表格时,我用文本填充单元格并应用对齐方式:

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

但是,文本没有正确垂直对齐。当我查看“格式表”下的“单元格属性”选项卡时,我看到它已经设置为“中间”垂直对齐,但只有在我点击“确定”后才会应用这个(如果我点击取消,没有任何变化)。

在应用对齐之前或之后更改文本都没有关系。有人对为什么会这样有任何想法吗?

4

1 回答 1

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
于 2016-11-24T14:00:17.980 回答