PowerPoint VBA - 定期从 Excel 更新链接图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5964813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PowerPoint VBA - Update linked graph from Excel at regular intervals
提问by Kenny Bones
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.
我正在尝试构建这个系统,其中包含来自外部 Excel 文件的链接图的 PowerPoint 演示文稿。我已经看到我可以在 PowerPoint 中右键单击此图表,然后单击“更新链接”,图表会自动更新。
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.
但是如果我想要这个自动化呢?如果这可以在不创建加载项的情况下完成,那就太好了。那么 PowerPoint 中有哪些事件处理程序?我想有一个 SlideChanged 或其他什么的事件?我可以让演示文稿无限循环并在每个新的滑动开关处更新链接吗?可能有大量的图表。每个图表部分一张幻灯片。
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.
或者,还有什么其他好主意?我正在尝试构建的系统基本上是一个用于收集数据并以可能需要的任何形式显示数据的框架。数据自动从经济软件导入数据库。所以我创建了一个命令行应用程序,它基本上打开一个 Excel 文件并运行一个宏(收集新数据并将其复制到工作表中)。此命令行应用程序设置为通过计划任务按特定时间运行。正是这些数据,我想自动显示图表。
I actually did a large bit of it myself :)
我实际上自己做了很多:)
Here's the code for VB.NET application (Can be used as command line application)
这是 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
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 :)
这显然是一个开始。我需要弄清楚它是否可以在幻灯片放映时完成。不过我觉得应该是可以的。当我设法获得值得一提的东西时会更新:)
回答by Steve Rindsberg
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.
更改底层幻灯片(即从外部 Excel 应用程序)应更新正在运行的节目;正在运行的节目中的当前幻灯片通常不会显示更新,除非您强制重绘,但是当它再次出现在节目中时,更新应该是可见的。
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.
总而言之,从 Excel 自动化 PPT 比让它控制事物并按需吸收更新更容易......至少除非您想包含一个加载项来处理 PPT 中的事件。