2017-02-14 122 views
0

我有一個PowerPoint演示文稿,其中有幾個Excel圖表粘貼爲鏈接。使用VBA,我已經檢查過了,這些形狀的類型是msoLinkedOLEObjectPowerpoint VBA:鏈接Excel圖表的開放源代碼

認識到這一點,我想先打開包含原始圖表通過VBA的Excel文件,然後使用圖表的「更新鏈接」命令,就像這樣:

enter image description here

祝首先打開工作簿,因爲使用「更新鏈接」命令和打開的Excel文件對我來說通常比​​直接使用「更新鏈接」命令更快(可能是因爲某些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 

回答

2

您可以使用

sld.Shapes(i).OLEFormat.Activate 

或者

sld.Shapes(i).OLEFormat.DoVerb 

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

雙方將打開鏈接的對象,所以你可以對其進行編輯。但請注意,這不足以引用可通過VBA操作的Excel對象。