通过PowerPoint自动化Excel - 本地窗口不暴露完整的对象模型(即Linksources)

bre*_*tdj 6 excel powerpoint vba excel-vba powerpoint-vba

背景

我正在运行代码(来自PowerPoint):

  • 循环播放演示文稿中的每张幻灯片.
  • 检查每个形状以确定它是否是图表.
  • 如果是图表,请激活基础Excel工作表,然后将此基础文件中的链接更改为新源.

我注意到excel的链接在整个PPT级别[via Info]中不存在,它们被故意链接到每个图表,以便可以在不访问源excel文件的情况下编辑演示文稿.

代码适用 - 广义上.

有一个持续的错误(代码运行正常),我认为是网络和内存稳定性(大约15个图表后失败),我希望关闭screenupdating按照关闭powerpoint的屏幕更新.

我访问的所有图表都链接到其他工作簿.然而,当Excel工作簿暴露给PowerPoint时,即使代码处理每个链接,链接也不会显示在Locals窗口中(下图显示链接存在)

我翻转了自动化以从Excel访问PowerPoint包,结果相同.没有Linksources.

在使用Excel自动化PowerPoint时,为什么在" 本地"窗口中也不能使用完整对象模型?

这是一个我偶然发现的局部故障,还是一个更广泛的问题?

下图显示了迭代链接的代码(ppl变量,但xlWB变量没有Linksources).

在此输入图像描述

Sub FastUpdate()

    Dim sld As Slide
    Dim shp As Shape
    Dim pptchrt As Chart
    Dim pptChrtData As ChartData

    Dim xlWB As Excel.Workbook
    Dim lngStart As Long
    Dim strNew As String
    Dim strMsg As String

    Dim ppl As Variant

    On Error GoTo cleanup
    'set start position manually 
    'lngStart = 34
    If lngStart = 0 Then lngStart = 1

    'call custom function for user to pick file
    'strNew = Getfile
     strNew = "S:\Corporate Model\05 RSM submissions\05 May 2016\02 Checked RSMs\VFAT\Australia\Australia - Valuation and Financial Analysis template.xlsx"


        For Each sld In ActivePresentation.Slides
            If sld.SlideIndex >= lngStart Then
                For Each shp In sld.Shapes
                    If shp.HasChart Then
                    Set pptchart = shp.Chart
                    Set pptChrtData = pptchart.ChartData
                    'open underlying excel file - doesn't just activate chart
                    pptChrtData.Activate
                    '
                    Set xlWB = pptChrtData.Workbook

                    'loop through all links
                    For Each ppl In xlWB.LinkSources
                        strMsg = strMsg & SlideNumber & " " & pptchart.Name & vbNewLine
                        xlWB.ChangeLink ppl, strNew
                    Next

                    xlWB.Close True
                    Set xlWB = Nothing
                    End If
                Next shp
            End If
        Next sld

cleanup:
Set xlWB = Nothing
If Err.Number <> 0 Then MsgBox Err.Description, vbCritical
If Len(strMsg) > 0 Then MsgBox strMsg, vbOKOnly, "Completed"
End Sub
Run Code Online (Sandbox Code Playgroud)

Bra*_*cku 3

局部变量和监视窗口显示对象的属性。Workbook 对象的属性列表可以在此处找到。

LinkSources是一个带有可选Type参数的方法。

如果你想调试,LinkSources可以将其添加到 Watch 窗口: 在此输入图像描述

或将返回值保存到局部变体变量以在“局部变量”窗口中查看它。