PowerPoint VBA - 定期更新 Excel 中的链接图
我正在尝试构建这个系统,其中包含来自外部 Excel 文件的链接图的 PowerPoint 演示文稿。我发现我可以在 PowerPoint 中右键单击该图表,然后单击“更新链接”,该图表就会自动更新。
但如果我想要自动化怎么办?如果这可以在不创建插件的情况下完成,那就太好了。那么 PowerPoint 中有哪些事件处理程序呢?我认为有一个 SlideChanged 活动或其他活动?我是否可以让演示文稿无限循环并在每个新的幻灯片切换时更新链接?可能有大量的图表。图表的每个部分都有一张幻灯片。
或者,还有其他好主意吗? 我正在尝试构建的系统基本上是一个用于收集数据并以任何可能需要的形式显示数据的框架。数据自动从经济软件导入到数据库中。因此,我创建了一个命令行应用程序,它基本上打开一个 Excel 文件并运行一个宏(收集新数据并将其复制到工作表中)。该命令行应用程序设置为通过计划任务在特定时间运行。我想自动显示这些数据的图表。
实际上我自己做了很多工作:)
这是 VB.NET 应用程序的代码(可以用作命令行应用程序)
Imports Microsoft.Office.Interop
Public Class Form1
Dim oPPTApp
Sub updatePPTGraph()
For Each oSlide In oPPTApp.ActivePresentation.Slides
For Each oShape In oSlide.shapes
If oShape.Type = 10 Then
oShape.LinkFormat.Update()
End If
Next
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oPPTApp = New PowerPoint.Application
oPPTApp.visible = True
Dim oPresentation As PowerPoint.Presentation
oPresentation = oPPTApp.Presentations.Open("C:\Users\kenny\Documents\Charttest.pptx")
updatePPTGraph()
End Sub
End Class
这显然是一个开始。我需要弄清楚是否可以在幻灯片放映时完成。但我认为这应该是可能的。当我设法得到一些值得一提的东西时会更新:)
I'm trying to build this system where I have this PowerPoint presentation with a linked graph from an external Excel file. I've seen that I can right click this graph in PowerPoint and click "Update link" and the graph is automatically updated.
But what if I want this automated? If this can be done without creating an Add-in that would have been great. So which event handlers are there in PowerPoint? I reckon there's an event for SlideChanged or something? Could I possibly have the presentation go in an endless loop and update the link at each new slide switch? There are possibly huge amounts of graphs. And one slide for each section of graphs.
Or, any other bright ideas?
The system I'm trying to build is basically a framework for collecting data and displaying it in whatever form that might be wanted. Data is automatically imported from an economy software and into a database. So I've created a command line application that basically opens an Excel file and runs a macro (collecting the fresh data and copy it into the worksheet). This command line application is set to run as specific times via Scheduled Tasks. And it's this data that I want to show graphs from, automatically.
I actually did a large bit of it myself :)
Here's the code for VB.NET application (Can be used as command line application)
Imports Microsoft.Office.Interop
Public Class Form1
Dim oPPTApp
Sub updatePPTGraph()
For Each oSlide In oPPTApp.ActivePresentation.Slides
For Each oShape In oSlide.shapes
If oShape.Type = 10 Then
oShape.LinkFormat.Update()
End If
Next
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oPPTApp = New PowerPoint.Application
oPPTApp.visible = True
Dim oPresentation As PowerPoint.Presentation
oPresentation = oPPTApp.Presentations.Open("C:\Users\kenny\Documents\Charttest.pptx")
updatePPTGraph()
End Sub
End Class
This is clearly a start. I need to figure out if it can be done while a slideshow is showing as well. But I think it should be possible. Will update when I manage to get something worth mentioning :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改底层幻灯片(即从外部 Excel 应用程序)应更新正在运行的演示;正在运行的演示中的当前幻灯片通常不会显示更新,除非您强制重画,但当它再次出现在演示中时,更新应该是可见的。
总而言之,从 Excel 自动化 PPT 比让它控制事物并按需吸收更新更容易……至少会这样,除非您想包含一个加载项来处理 PPT 中的事件。
Changing the underlying slides (ie from an external Excel app) should update the running show; the current slide in the running show won't usually show the update unless you force a redraw, but when it comes around in the show again, the update should be visible.
All told, it'd be easier to automate PPT from Excel than to let it control things and suck the updates in on demand ... at least it would unless you want to include an add-in to handle events in PPT.