Dim myPresentation, mySlide, PowerPointApp, shp As Object
Dim MySlideArray, MyRangeArray As Variant
Dim x As Long
Set myPresentation = PowerPointApp.ActivePresentation
MySlideArray = Array(1, 2, 3, 4)
MyRangeArray = Array(Worksheets("Name File").Range("A1:C10"), _
Worksheets("Age File").Range("A1:C10"), _
Worksheets("Location File").Range("A1:C10"), _
Worksheets("DOB File").Range("A1:C10"))
For x = LBound(MySlideArray) To UBound(MySlideArray)
MyRangeArray(x).Copy
Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange
Next x
Application.CutCopyMode = False
ThisWorkbook.Activate
在调试时,有时代码会一直运行,但只有第一个范围会被复制到powerpoint,而其余的则不会。有时,我在使用ShapeRange(粘贴(时遇到运行时错误。我哪里做错了?请帮忙。从1周开始学习VBA。错误看起来像这个
看起来您想要复制MyRangeArray
中引用的每个范围,并将它们复制到MySlideArray
中引用的相应幻灯片中。
下面的代码行将把每个范围粘贴到各自的幻灯片中,并返回一个ShapeRange
。
Set shp = myPresentation.slides(MySlideArray(x)).Shapes.Paste
要返回Shape
对象,请尝试以下操作。。。
Set shp = myPresentation.slides(MySlideArray(x)).Shape`s.Paste(1)
顺便说一下,myPresentation
、mySlide
和PowerPointApp
被声明为Variant
,因为您还没有指定类型。要将它们声明为Object
,您需要指定以下类型。。。
Dim myPresentation as Object, mySlide as Object, PowerPointApp as Object, shp As Object
同样的事情也适用于您的下一个申报行。