在选定的(或范围的)Powerpoint 幻灯片上循环图表 [英] Loop Through Charts on Selected (or Range of) Powerpoint Slides

查看:48
本文介绍了在选定的(或范围的)Powerpoint 幻灯片上循环图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此代码更新我的 powerpoint 演示文稿中的所有链接:

I am currently using this code to update all links in my powerpoint presentation:

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 上的图表?

Instead of updating the link of every chart in the presentation, is it possible to have this code loop through only selected slides? Or if it's easier - is it possible to set a range? For example, only update charts on slides 15-30?

谢谢!

评论中提供的解决方案 - 这是我修改后的代码

Resolution provided in comments - here is my revised code

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

推荐答案

是的,您可以SlidesShapes 上组合自定义范围>,使用 Array 作为 index 参数.试试这个:

Yes you can compose custom ranges on Slides as well as on Shapes, using an Array as the index parameter. Try this:

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

输出:

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

Slide2 Slide4 Slide6

附言我删除了测试演示文稿中的一张幻灯片.

p.s. I had deleted a slide in the test presentation.

这篇关于在选定的(或范围的)Powerpoint 幻灯片上循环图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆