1

我目前正在使用此代码更新我的 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
4

2 回答 2

1

是的,您可以使用 an作为参数来编写自定义范围 onSlides和 on 。尝试这个:ShapesArrayindex

Dim sld As Slide
For Each sld In ActivePresentation.Slides.Range(Array(1, 3, 5))
    Debug.Print sld.Name
Next

输出:

幻灯片 2 幻灯片 4 幻灯片 6

ps 我在测试演示中删除了一张幻灯片。

于 2017-02-07T17:33:34.523 回答
0

由于您还提到只处理选定的幻灯片,您可以这样做:

Sub SelectedSlides()
    Dim osl As Slide
    For Each osl In ActiveWindow.Selection.SlideRange
        Debug.Print osl.SlideIndex
    Next
End Sub

请注意,这将以 REVERSE 选择顺序为您提供选定的幻灯片。也就是说,如果您按住 Control 键单击幻灯片 2、4、6,这将为您提供 6、4、2。

于 2017-02-08T16:22:00.877 回答