开发者

PowerPoint VBA - Update linked graph from Excel at regular intervals

开发者 https://www.devze.com 2023-03-04 08:32 出处:网络
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 \"Updat

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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号