使用vba将excel范围复制到powerpoint

时间:2017-07-17 15:22:55

标签: excel vba copy range powerpoint

我要将一系列打开的Excel电子表格复制到开放式powerpoint。当我运行代码时,我收到消息"编译错误 - 用户定义的类型未定义"我很新,而且我不知道如何解决它。

Sub Importdatau()

'declare the variables
    Dim activePowerPoint As PowerPoint.Application
    Dim activeSlide As PowerPoint.Slide
    Dim cht As Excel.ChartObject
    Dim rng As Range

 'Copy Range from Excel

设置rng = ThisWorkbook.ActiveSheet.Range(" A1:m30")

 'Look for existing instance
    On Error Resume Next
    Set newPowerPoint = GetObject(, "PowerPoint.Application")
    On Error GoTo 0

'Show the PowerPoint
    newPowerPoint.Visible = True

    'Add a new slide where we will paste the chart
        newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
        newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
        Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)

    'Copy the chart and paste it into the PowerPoint as a Metafile Picture
        rng.Copy
        activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select


    'Adjust the positioning of the Chart on Powerpoint Slide
        newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 0
        newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 0

        activeSlide.Shapes(2).Width = 200
        activeSlide.Shapes(2).Left = 505

0 个答案:

没有答案