VB 编码的宏无法在 PowerPoint 中运行

问题描述 投票:0回答:1

我在 PowerPoint 中运行宏时遇到困难。我希望宏将幻灯片中的表格设置为 14 厘米的高度。这是我的代码:

Sub AdjustTableHeight()
    Dim tbl As ListObject 
    Set tbl = ThisWorkbook.Worksheets("Sheet1").ListObjects("Table1") ' 

    ' Set the height of the table to 14 cm
    tbl.TableStyle = "TableStyleMedium1" '
    tbl.TableObject.RowSizing = xlFixedHeight
    tbl.TableObject.Height = Application.CentimetersToPoints(14)
End Sub

但是当我运行它时什么也没有发生

vba powerpoint
1个回答
0
投票

OP中的代码是Excel VBA代码。下面的代码设置 PPT 活动窗口中的表格高度。

Option Explicit
Sub SetTableHeight()
    Dim slide As slide, tbl As Table
    Dim shp As Shape, i As Integer
    Dim tabHeight As Double, rowHeight As Double
    tabHeight = 14
    ' Get the current active slide
    Set slide = Application.ActiveWindow.View.slide
    For Each shp In slide.Shapes
        ' Check if the slide contains a table
        If shp.HasTable Then
            ' Get the first table on the slide
            Set tbl = shp.Table
            ' convert CM to Point
            rowHeight = tabHeight * 28.35 / tbl.Rows.Count
            ' set row height
            For i = 1 To tbl.Rows.Count
                tbl.Rows(i).Height = rowHeight
            Next
        Else
            MsgBox "There are no tables on the slide."
        End If
    Next
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.