基于链接的Excel文件的Powerpoint VBA更新动态范围图源

时间:2018-10-16 18:47:03

标签: vba charts powerpoint

我正在使用以下代码在PowerPoint演示文稿中选择幻灯片,并将这些幻灯片上的图表链接到Excel文件,因为我每个月的数据都在变化。该代码很好用。

Sub UpdateLinks()
Dim ExcelFile
Dim exl As Object
Set exl = CreateObject("Excel.Application")
Dim sld As Slide

ExcelFile = "C:\Users\J\SampleSourceFile.xlsm"

Dim i As Integer
Dim shp As Shape



Dim L As Long
Dim rayFixed() As Variant
Dim sldR As SlideRange
Dim strInput As String
Dim raySlides() As Long
strInput = InputBox("Input slides to select")
rayFixed = getArray(strInput)
ReDim raySlides(0 To UBound(rayFixed))
For L = 0 To UBound(rayFixed)
raySlides(L) = CLng(rayFixed(L))
Next L

Set sldR = ActivePresentation.Slides.Range(raySlides)


 For Each sld In sldR
 'Go through every slide

         'Go through every shape on every slide
        For Each shp In sld.Shapes
On Error Resume Next
             'Set the source to be the same as teh file chosen in the 
opening dialog box
            shp.LinkFormat.SourceFullName = ExcelFile
            If shp.LinkFormat.SourceFullName = ExcelFile Then
                 'If the change was successful then also set it to update 
automatically
                shp.LinkFormat.Update
                'other option is ppUpdateOptionManual
            End If

        Next shp


Next

End Sub'

但是,每个月我都会在excel文件中添加一些图表。例如,last month我的图表来源是=Tenure!$O$1:$Y$8,而this month=Tenure!$O$1:$Z$8

=Tenure!$O$1:$Y$8部分正确更新,但是Z column不存在。 即使在链接的excel文件中是准确的,powerpoint仍使我手动选择数据并更改坐标,因为powerpoint存储了我以前使用的内容(甚至在取消链接/重新链接之后)。我必须为多个图表复制相同的操作,并且想知道是否可以使用任何代码来更新范围,而不必手动单击图表(即使它在单独的模块中-我不介意更新代码新范围的每个月,但相同的图表通常在不同的#幻灯片上,具体取决于广告组)。

0 个答案:

没有答案