使用VBA将所有幻灯片图片保存到单个JPG图像中

时间:2018-06-05 17:45:52

标签: vba powerpoint

我想在VBA powerPoint中执行以下操作:

我有一个带有六张照片的powerPoint。理想情况下,我想将六张图片分组为.jpg创建一张新图片,然后将.jpg图片导出到文件中。导出照片后,我想删除6张单独的图片,以便我可以导入单张.jpg图片。

我用它开始:Save all Shapes of slide into single JPG image。我理解评论,但不知道如何执行它。

如果有更好的方法,请分享。

谢谢!

1 个答案:

答案 0 :(得分:0)

这会将当前选定的形状转换为PNG,将其粘贴回幻灯片并删除原始形状。

你可能想要修改它以确保选择某些内容并且如果没有正常退出,或者它只是为了你自己的使用,让PPT / VBA骂你,如果你忘记选择某些内容。

Sub ConvertSelectionToImage()

    Dim oShapes As ShapeRange
    Dim oGroup As Shape
    Dim oSingleShape As Shape

    ' Get a reference to the selected shapes
    Set oShapes = ActiveWindow.Selection.ShapeRange
    ' Group them so we can later pick up their coordinates
    Set oGroup = oShapes.Group
    ' copy to clipboard
    oGroup.Copy

    ' paste from clipboard as PNG to retain transparency
    Set oSingleShape = ActiveWindow.Selection.SlideRange.Shapes.PasteSpecial(ppPastePNG)(1)

    ' Position the pasted PNG to match original shapes
    With oSingleShape
        .Left = oGroup.Left
        .Top = oGroup.Top
    End With

    ' And delete the original shapes
    oGroup.Delete

End Sub