如何使用 VBA 在 PowerPoint 2003 中复制行?

发布于 2024-12-07 08:24:51 字数 342 浏览 0 评论 0原文

我需要在 PowerPoint 2003 中复制行(只是为了重新使用它们的格式)。尝试这样做:

Dim oPPTRow As PowerPoint.Row

Set oPPTRow = oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows(2)
oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows.Add (-1)
oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows(oPPTTable.Rows.Count) = oPPTRow

但没有成功。还有其他方法可以达到同样的效果吗?

I need to copy rows in PowerPoint 2003 (just to re-use their formatting). Tried to do:

Dim oPPTRow As PowerPoint.Row

Set oPPTRow = oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows(2)
oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows.Add (-1)
oPPTFile.Slides(SlideNum).Shapes(1).Table.Rows(oPPTTable.Rows.Count) = oPPTRow

But it doesn't work. Is there any other way to achieve the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假扮的天使 2024-12-14 08:24:51

Rows.Add 方法允许您在所需的任何行之前插入新行。新插入的行将采用您之前插入的行的格式。试试这个(一定要先选择一个表格形状):

Sub AddNewRow()
    Dim oTbl As Table
    Dim oSh As Shape

    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Set oTbl = oSh.Table

    With oTbl
        .Rows.Add (2)
    End With
End Sub

将 -1 作为参数传递给 .Add 强制 PPT 在表格末尾添加行;新单元格的格式将与其上面的单元格相同(即,之前位于底行的行中的单元格)。

如果您需要从其他行获取格式,我认为您可能需要执行以下操作:

Sub AddNewRow()
    Dim oTbl As Table
    Dim oSh As Shape
    Dim x As Long
    Dim lNewRow As Long

    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Set oTbl = oSh.Table

    With oTbl
        .Rows.Add (-1)
        lNewRow = .Rows.Count
        ' format the new row to match the cells in row two
        With .Rows(lNewRow)
            ' step across the row cell by cell
            For x = 1 To oTbl.Columns.Count

                ' pick up row two formatting
                oTbl.Cell(2, x).Shape.PickUp
                ' apply it to new row's cell x
                .Cells(x).Shape.Apply

                ' do the same for cell's text formatting
                oTbl.Cell(2, x).Shape.TextFrame.TextRange.Font.Name = oTbl.Cell(2, x).Shape.TextFrame.TextRange.Font.Name
                ' Use above pattern to pick up/apply font bold, ital, size, color etc as needed
            Next
        End With
    End With
End Sub

The Rows.Add method lets you insert a new row before any row you like. The newly inserted row will pick up the formatting of the row you inserted it ahead of. Try this (be sure to select a tabel shape first):

Sub AddNewRow()
    Dim oTbl As Table
    Dim oSh As Shape

    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Set oTbl = oSh.Table

    With oTbl
        .Rows.Add (2)
    End With
End Sub

Passing -1 as the parameter to .Add forces PPT to add the row at the end of the table; the new cells will all be formatted the same as the cells above them (that is, the cells in the row that was previously the bottom row).

If you need to pick up formatting from some other row, I think you may need to do something like:

Sub AddNewRow()
    Dim oTbl As Table
    Dim oSh As Shape
    Dim x As Long
    Dim lNewRow As Long

    Set oSh = ActiveWindow.Selection.ShapeRange(1)
    Set oTbl = oSh.Table

    With oTbl
        .Rows.Add (-1)
        lNewRow = .Rows.Count
        ' format the new row to match the cells in row two
        With .Rows(lNewRow)
            ' step across the row cell by cell
            For x = 1 To oTbl.Columns.Count

                ' pick up row two formatting
                oTbl.Cell(2, x).Shape.PickUp
                ' apply it to new row's cell x
                .Cells(x).Shape.Apply

                ' do the same for cell's text formatting
                oTbl.Cell(2, x).Shape.TextFrame.TextRange.Font.Name = oTbl.Cell(2, x).Shape.TextFrame.TextRange.Font.Name
                ' Use above pattern to pick up/apply font bold, ital, size, color etc as needed
            Next
        End With
    End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文