VBA粘贴Excel选定工作表范围到活动的PowerPoint幻灯片中(PowerPoint VBA)


Sub RangeToPresentation()
' Set a VBE reference to Microsoft Excel Object Library
    Dim XLApp As Excel.Application
    Dim PPSlide As Slide
    ' Reference existing instance of Excel
    Set XLApp = GetObject(, "Excel.Application")

    ' Make sure a range is selected
    If Not TypeName(XLApp.Selection) = "Range" Then
        MsgBox "Please select a worksheet range and try again.", _
            vbExclamation, "No Range Selected"
        ' Can only paste into slide view
        Application.ActiveWindow.ViewType = ppViewSlide
        ' Reference active slide
        Set PPSlide = ActivePresentation.Slides _
        ' Copy the range as a piicture
        XLApp.Selection.CopyPicture Appearance:=xlScreen, _
        ' Paste the range
        ' Align the pasted range
        Application.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        Application.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
        ' Clean up
        Set PPSlide = Nothing
    End If
    Set XLApp = Nothing
End Sub