Powerpoint VBA:链接 Excel 图表的开源

Powerpoint VBA: Open Source of Linked Excel Chart

我有一个 PowerPoint 演示文稿,其中有几个 Excel 图表作为链接粘贴。使用VBA,我检查过,这些形状的类型是msoLinkedOLEObject

知道这一点,我想先通过VBA打开包含原始图表的Excel文件,然后使用图表的"update link"命令,像这样:

我想先打开工作簿,因为使用 "update link" 命令打开 Excel 文件通常比直接使用 "update link" 命令更快(可能是因为一些PowerPoint 演示文稿和一些工作簿真的很丰富)。

sld.Shapes(i).LinkFormat部分代码,我可以用.UpdateLinks直接刷新数据,但是找不到直接打开Excel源文件的方法(在与我手动单击链接图表的方式相同。

这能实现吗?

Sub UpdateExcelLinkedCharts()
Dim pres As Presentation
Dim sld As Slide
Dim shp As Shape

Set pres = Application.ActivePresentation

'Loop through all active slides in the presentation
For Each sld In pres.Slides
If sld.SlideShowTransition.Hidden = msoFalse Then

'If the slide is a msoLinkedOLEObject, proceed to update its link
For i = 1 To sld.Shapes.Count

If sld.Shapes(i).Type = 10 Then
sld.Shapes(i).LinkFormat.UpdateLinks

End If

Next i

End If

Next sld


MsgBox ("All Links Updated!")
End Sub

您可以使用

sld.Shapes(i).OLEFormat.Activate

或者

sld.Shapes(i).OLEFormat.DoVerb

其次是sld.Shapes(i).LinkFormat.Update

两者都会打开链接的对象,以便您对其进行编辑。但是请注意,这不足以引用您可以通过 VBA.

操作的 Excel 对象