本文介绍了如何在使用"for"功能复制excel表时添加新幻灯片从Excel VBA循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim myPresentation As Object
Dim mySlide As Object
Dim PowerPointApp As Object
Dim shp As Object
Dim MySlideArray As Variant
Dim MyRangeArray As Variant
Dim x As Long
PowerPointApp.ActiveWindow.Panes(1).Activate
Set myPresentation = PowerPointApp.ActivePresentation
MySlideArray = Array(1, 2)
MyRangeArray = Array(Worksheets("name").Range("A3:E17"), Worksheets("age").Range("A22:E37"))
For x = LBound(MySlideArray) To UBound(MySlideArray)
MyRangeArray(x).Copy
Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2)
Set myPresentation = PowerPointApp.ActivePresentation.AddSlide(PowerPointApp.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank).Select
Next x
问题1)错误是仅在 Count + 1.select
行处出现对象不支持此属性或方法".我怎么了?
Question 1) The error is "Object doesn't support this prop or method" just at the Count+1.select
line. What is my mistake?
问题2)如果我要粘贴在相同幻灯片中的相同工作表中的两个单元格区域"A1:E9"和"A11:E20",有没有办法编写代码以从A1中查找非空单元格并将数据复制到最后填充的行并粘贴到powerpoint中?
Question 2) If i have two ranges of cells "A1:E9" and "A11:E20" in same sheet that i want to paste in same slide, is there a way to write code which looks for non-empty cells from A1 and copies data till the last filled row and paste in powerpoint?
很长的问题的道歉.会很乐意得到任何答案.
Apologies for the long question. Will be happy to get any answer.
推荐答案
这有几处错误:
- 您之前已经
设置了myPresentation = PowerPointApp.ActivePresentation
.我想你的意思是mySlide
. -
PowerPointApp.ActivePresentation
-使用myPresentation
,这是多余的. - 该方法为
Slides.AddSlide
,而不是Application.AddSlide
或Presentation.AddSlide
. - ...但是您想要
Slides.Add
,因为AddSlide
将CustomLayout
作为其第二个参数. -
PowerPointApp.Slides.Count
-应用程序没有Slides
属性;应该是myPresentation.Slides.Count
. -
PowerPoint.PpSlideLayout.ppLayoutBlank
-请注意,此早期绑定,而其余代码则使用 late-binding .(将myPresentation设置为对象
,将mySlide设置为对象
等).最好保持一致.我制定了一种早期约束方法
- You already
Set myPresentation = PowerPointApp.ActivePresentation
previously. I think you meantmySlide
. PowerPointApp.ActivePresentation
- usemyPresentation
, this is redundant.- The method is
Slides.AddSlide
, notApplication.AddSlide
orPresentation.AddSlide
. - ...but you want
Slides.Add
sinceAddSlide
takes aCustomLayout
as its second parameter. PowerPointApp.Slides.Count
- there's noSlides
property of the application; that should bemyPresentation.Slides.Count
.PowerPoint.PpSlideLayout.ppLayoutBlank
- note that this early-binding, while the rest of your code uses late-binding. (Dim myPresentation As Object
,Dim mySlide As Object
, etc.). Best to be consistent. I've laid out an early-binding approach
具有这些修订版本:
Const ppLayoutBlank as Long = 12
With myPresentation.Slides
Set mySlide = .Add(.Count + 1, ppLayoutBlank)
End With
这篇关于如何在使用"for"功能复制excel表时添加新幻灯片从Excel VBA循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!