简体   繁体   English

Powerpoint VBA:链接的Excel图表的开源

[英]Powerpoint VBA: Open Source of Linked Excel Chart

I have a PowerPoint presentation with several Excel charts pasted as links. 我有一个PowerPoint演示文稿,其中粘贴了几个Excel图表作为链接。 Using VBA, I have checked, and the type of these shapes is msoLinkedOLEObject . 我已经使用VBA进行了检查,这些形状的类型是msoLinkedOLEObject

Knowing this, I would like to first open the Excel file that contains the original chart through VBA and then use the "update link" command of the chart, like this: 知道这一点后,我想首先通过VBA打开包含原始图表的Excel文件,然后使用图表的“更新链接”命令,如下所示:

在此处输入图片说明

I wish to open the workbooks first because using the "update link" command with an open Excel file is usually faster for me than just using the "update link" command directly (maybe because some PowerPoint presentations and some workbooks are really extense). 我希望首先打开工作簿,因为对我来说,将“更新链接”命令与打开的Excel文件一起使用通常比直接使用“更新链接”命令要快(可能是因为某些PowerPoint演示文稿和某些工作簿确实很扩展)。

For the sld.Shapes(i).LinkFormat part of the code, I can use .UpdateLinks to directly refresh the data, but I cannot find any way to directly open the Excel source file (in the same way I can by manually clicking the linked chart). 对于代码的sld.Shapes(i).LinkFormat部分,我可以使用.UpdateLinks直接刷新数据,但是找不到任何直接打开Excel源文件的方法(通过手动单击该方法的相同方法链接的图表)。

Could this be achieved? 可以实现吗?

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

You can either use 您可以使用

sld.Shapes(i).OLEFormat.Activate

Or 要么

sld.Shapes(i).OLEFormat.DoVerb

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

Both will open the linked object so you can edit it. 两者都将打开链接的对象,以便您可以对其进行编辑。 But notice that this is not enough to have a reference to an Excel Object that you can manipulate through VBA. 但是请注意,这不足以引用可通过VBA进行操作的Excel对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM