[英]Loop Through Charts on Selected (or Range of) Powerpoint Slides
我目前正在使用此代碼更新我的 powerpoint 演示文稿中的所有鏈接:
Sub UpdateLinks()
Dim ExcelFile
Dim exl As Object
Set exl = CreateObject("Excel.Application")
ExcelFile = "C:\Users\J\Documents\Reporting\Governance Physical Charts.xlsm"
Dim i As Integer
Dim k As Integer
'Go through every slide
For i = 1 To ActivePresentation.Slides.Count
With ActivePresentation.Slides(i)
'Go through every shape on every slide
For k = 1 To .Shapes.Count
On Error Resume Next
'Set the source to be the same as teh file chosen in the opening dialog box
.Shapes(k).LinkFormat.SourceFullName = ExcelFile
If .Shapes(k).LinkFormat.SourceFullName = ExcelFile Then
'If the change was successful then also set it to update automatically
.Shapes(k).LinkFormat.AutoUpdate = ppUpdateOptionAutomatic 'other option is ppUpdateOptionManual
End If
Next k
End With
Next i
End Sub
除了更新演示文稿中每個圖表的鏈接之外,是否可以讓此代碼僅循環播放選定的幻燈片? 或者如果它更容易 - 是否可以設置一個范圍? 例如,只更新幻燈片 15-30 上的圖表?
謝謝!
編輯:評論中提供的解決方案 - 這是我修改后的代碼
Sub UpdateLinks()
Dim ExcelFile
Dim exl As Object
Set exl = CreateObject("Excel.Application")
Dim sld As Slide
ExcelFile = "C:\Users\J\Documents\Reporting\Governance Physical Charts.xlsm"
Dim i As Integer
Dim shp As Shape
For Each sld In ActivePresentation.Slides.Range(Array(11, 12, 13, 14, 15, 16, 17, 18))
For Each shp In sld.Shapes
On Error Resume Next
shp.LinkFormat.SourceFullName = ExcelFile
If shp.LinkFormat.SourceFullName = ExcelFile Then
shp.LinkFormat.AutoUpdate = ppUpdateOptionAutomatic 'other option is ppUpdateOptionManual
End If
Next shp
Next
End Sub
是的,您可以使用Array
作為index
參數在Slides
和Shapes
上組合自定義范圍。 嘗試這個:
Dim sld As Slide
For Each sld In ActivePresentation.Slides.Range(Array(1, 3, 5))
Debug.Print sld.Name
Next
輸出:
幻燈片 2 幻燈片 4 幻燈片 6
ps 我在測試演示中刪除了一張幻燈片。
由於您還提到僅處理選定的幻燈片,您可以這樣做:
Sub SelectedSlides()
Dim osl As Slide
For Each osl In ActiveWindow.Selection.SlideRange
Debug.Print osl.SlideIndex
Next
End Sub
請注意,這將以相反的選擇順序為您提供選定的幻燈片。 也就是說,如果您按住 Control 鍵單擊幻燈片 2、4、6,則會得到 6、4、2。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.