Update Excel object in PowerPoint

3.6k Views Asked by At

I have a PowerPoint presentation which has Excel tables as objects.

The Excel files are updated once a week. Once Excel files are updated, I open PowerPoint, double-click on each object -> menu Data -> Edit Links -> select all sources -> Update Values.

Is it possible for a macro to find the Excel objects in PowerPoint and update them?

After searching the web I've managed to get the following code which takes me up to the step of double clicking the object, but I don't know how to update links.

Sub update_objects()

    Dim it As String
    Dim i As Integer
    For i = 1 To ActiveWindow.Selection.SlideRange.Shapes.Count
        With ActiveWindow.Selection.SlideRange.Shapes(i)
            If .Type = msoEmbeddedOLEObject Then
                ActiveWindow.Selection.SlideRange.Shapes(i).Select.OLEFormat.DoVerb
            End If
        End With
    Next i
End Sub
2

There are 2 best solutions below

0
mooseman On

This code works, but not in all instances. It was written for 2010. Change the Type as needed. 7 is Excel Embedded objects.

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub open_and_close_all_objects()
    'This will open and then close all charts and graphs in the presentation to allow them to keep the data
    'Why this is needed is a question to be answered in the future.


    Dim oSH As Shape
    Dim oSl As Slide
    Dim oSheet As Object


    For Each oSl In ActivePresentation.Slides
        For Each oSH In oSl.Shapes

        ActiveWindow.View.GotoSlide oSl.Slideindex
             If oSH.Type = 7 Then
                oSH.Select
                oSH.OLEFormat.Activate

                Call Sleep(1500)

                ActiveWindow.Selection.Unselect
                ActiveWindow.View.GotoSlide oSl.Slideindex
            End If

        Next


     Next
     End Sub
0
David D. On

To use Sleep function, do this:

#If VBA7 Then ' Excel 2010 or later
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
#Else ' Excel 2007 or earlier
Public Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
#End If

From: https://www.educba.com/vba-sleep/