Publisher VBA垂直文本对齐属性不适用

时间:2016-11-15 21:47:30

标签: vba ms-publisher

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

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

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

如果在应用对齐之前或之后更改文本,则无关紧要。任何人都对为什么会这样做有任何想法?

1 个答案:

答案 0 :(得分:0)

好像你发现了一个bug。这是尝试解决方法..

#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