我有一个PowerPoint演示文稿,它只有很少的Excel表作为对象。 Excel文件每周更新一次。更新Excel文件后,我需要打开PowerPoint,双击每个对象 - >菜单数据 - >编辑链接 - >选择所有来源 - >更新值。
我最近开始在Excel中使用VBA,所以想知道是否可以编写一个宏来查找PowerPoint中的所有Excel对象并更新它们。
在搜索网页后,我设法获得以下代码,这些代码会让我双击对象,但我不知道如何更新链接。
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
答案 0 :(得分:0)
此代码有效,但并非在所有情况下都有效。它写于2010年。 根据需要更改类型。 7是Excel Embedded对象。
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