使用vba将excel范围复制到powerpoint
我正在尝试将一系列打开的excel电子表格复制到打开的powerpoint。当我运行代码时,我得到消息“compileerror-User defined type not defined”(编译错误-用户定义类型未定义)。我是一个新手,不知道如何修复它 子进口数据() Set rng=thiswoolk.ActiveSheet.Range(“A1:m30”)使用vba将excel范围复制到powerpoint,excel,vba,copy,range,powerpoint,Excel,Vba,Copy,Range,Powerpoint,我正在尝试将一系列打开的excel电子表格复制到打开的powerpoint。当我运行代码时,我得到消息“compileerror-User defined type not defined”(编译错误-用户定义类型未定义)。我是一个新手,不知道如何修复它 子进口数据() Set rng=thiswoolk.ActiveSheet.Range(“A1:m30”) 您是否设置了对Microsoft PowerPoint xx.x对象库的引用(VBE>工具>引用)?您好,多米尼克,谢谢您的回复。是的,
您是否设置了对Microsoft PowerPoint xx.x对象库的引用(VBE>工具>引用)?您好,多米尼克,谢谢您的回复。是的,设置了引用。哪一行导致了错误?我从“Sub”开始接收到消息,消息变为黄色,并且它不显示任何其他行。代码的其他部分也应该以蓝色突出显示,可能是Excel.ChartObject,这意味着您缺少对Microsoft Excel对象库的引用。你从哪里运行代码?如果从PowerPoint运行,则需要设置对Microsoft Excel对象库的引用。
'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
'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