用于格式化表格的Powerpoint宏(位置,大小,字体,对齐方式)

时间:2017-01-11 14:15:02

标签: formatting powerpoint-vba

我有一张包含大约10张幻灯片的PowerPoint,每张幻灯片都有一张需要以相同方式格式化的表格。我使用下面的宏来格式化表格中的文本,但我不知道如何将此代码与其他格式(如行高和表位置)结合起来。

有人可以通过在以下代码中添加以下首选项来帮助我:

  • 表水平位置=左起1厘米
  • 表垂直位置=距离顶部3厘米
  • 表宽= 23.5厘米
  • 表格发送回来
  • 所有行高度尽可能小
  • 所有文字中间对齐(垂直)

    Sub format()
    
    Dim s As Slide
    Dim oSh As Shape
    Dim oTbl As Table
    Dim lRow As Long
    Dim lCol As Long
    
    For Each s In ActivePresentation.Slides
        For Each oSh In s.Shapes
            If oSh.HasTable Then
                Set oTbl = oSh.Table
                For lRow = 1 To oTbl.Rows.Count
                    For lCol = 1 To oTbl.Columns.Count
                        With oTbl.Cell(lRow, lCol).Shape.TextFrame.TextRange
                            .Font.Name = "Calibri"
                            .Font.Size = 7
                        End With
                    Next
                Next
            End If
        Next    ' Shape
    Next s
    End Sub
    

2 个答案:

答案 0 :(得分:0)

我已经玩了一些,我已经回答了我自己的问题:

Sub format()

Dim s As Slide
Dim oSh As Shape
Dim oTbl As Table
Dim lRow As Long
Dim lCol As Long

For Each s In ActivePresentation.Slides
    For Each oSh In s.Shapes
        If oSh.HasTable Then
            oSh.Left = 1 * 28.3
            oSh.Top = 3 * 28.3
            oSh.Width = 23.5 * 28.35
            oSh.ZOrder msoSendToBack
            Set oTbl = oSh.Table
            For lRow = 1 To oTbl.Rows.Count
               For lCol = 1 To oTbl.Columns.Count
                With oTbl.Cell(lRow, lCol).Shape
                    .TextFrame.TextRange.Font.Name = "Calibri"
                    .TextFrame.TextRange.Font.Size = 7
                    .TextFrame2.VerticalAnchor = msoAnchorMiddle
                    oTbl.Rows(lRow).Height = 0.5
                    End With
                Next lCol
            Next lRow
        End If
    Next oSh    
Next s

End Sub

答案 1 :(得分:0)

我看到你想通了(干得好!)。另一个与您的需求相关的有用的事情"所有行高尽可能小"就是这样做:

oSh.Height = 0

...有时候会有几次,具体取决于表格的内容。