如何在使用"for"功能复制excel表时添加新幻灯片从Excel VBA循环? [英] How to add new slide while copying excel tables using "for" loop from Excel vba?

查看:93
本文介绍了如何在使用"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.AddSlide(PowerPointApp.Slides.Count + 1,PowerPoint.PpSlideLayout.ppLayoutBlank).选择

这有几处错误:

  1. 您之前已经设置了myPresentation = PowerPointApp.ActivePresentation .我想你的意思是 mySlide .
  2. PowerPointApp.ActivePresentation -使用 myPresentation ,这是多余的.
  3. 该方法为 Slides.AddSlide ,而不是 Application.AddSlide Presentation.AddSlide .
  4. ...但是您想要 Slides.Add ,因为 AddSlide CustomLayout 作为其第二个参数.
  5. PowerPointApp.Slides.Count -应用程序没有 Slides 属性;应该是 myPresentation.Slides.Count .
  6. PowerPoint.PpSlideLayout.ppLayoutBlank -请注意,此早期绑定,而其余代码则使用 late-binding .(将myPresentation设置为对象将mySlide设置为对象等).最好保持一致.我制定了一种早期约束方法
  1. You already Set myPresentation = PowerPointApp.ActivePresentation previously. I think you meant mySlide.
  2. PowerPointApp.ActivePresentation - use myPresentation, this is redundant.
  3. The method is Slides.AddSlide, not Application.AddSlide or Presentation.AddSlide.
  4. ...but you want Slides.Add since AddSlide takes a CustomLayout as its second parameter.
  5. PowerPointApp.Slides.Count - there's no Slides property of the application; that should be myPresentation.Slides.Count.
  6. 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循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆