这绝对是可能的,而且很有趣:-)
我的第一个建议是使用主视图创建一个PPT模板,占位符和标题都准备好了。
然后运行以下 powerpoint 宏,以便您可以获取页面上每个形状的名称和索引/id。
Sub nameshapes()
Dim sld As Slide
Dim shp As Shape
Set sld = Application.ActivePresentation.Slides(1)
For Each shp In sld.Shapes
shp.TextEffect.Text = shp.name & " " & shp.ID
Next
End Sub
这是一段快速而肮脏的代码,它将模板页面上每个项目的索引和名称放入形状本身。记忆,记录这些。这些是您想要的东西去哪里的参考点。
我不打算介绍循环等的基础知识,而是介绍关键代码。
1) 从 excel 打开并获得对 powerpoint 的控制。
Set ppt = CreateObject("PowerPoint.Application")
ppt.Visible = True
Set myPPT = ppt.Presentations.add
myPPT.ApplyTemplate ("Your template here.potx")
然后我添加我需要的所有页面,(这可能因您的应用程序和行数而异,以及您是在开始时还是在过程中执行此操作,取决于您是否已映射您应该将数据放在哪个页面上,在您的数据中)
For x = 1 To NumberOfPages
myPPT.Slides.AddSlide x, myPPT.SlideMaster.CustomLayouts(2) '2 is the index of the template I wish to use (in master views, the index is the order they're in (starting from 1)
Next
我假设您知道要在每一行更新哪个页面,所以:
For Each dr In .rows 'I'm storing my data in a special collection, you will need to adapt this
Set currSlide = myPPT.Slides(dr.cell("OutputPage").Value) 'go to the right page
Sheets(dr.cell("SheetName").toString).Activate 'make sure the data you want is active
ActiveSheet.Range(Names(dr.cell("ChartID").Value)).CopyPicture 'copy the table as a picture, this is easiest for formatting in powerpoint, but you can do lots of things here
currSlide.Select
currSlide.Shapes("Content Placeholder " & dr.cell("Output Position").toString).Select 'the output position is the index from the first bit of code,
ppt.ActiveWindow.View.Paste
next
现在,您的应用程序肯定会有所不同,但我希望所有基本必需品都在那里,这应该是一个很好的起点。