通过 PowerPoint 实现自动化 Excel - Locals window 未公开完整的对象模型(即 Linksources)
Automating Excel via PowerPoint - Locals window not exposing full Object model (ie Linksources)
背景
我是 运行 代码(来自 PowerPoint):
- 循环浏览演示文稿中的每张幻灯片。
- 检查每个形状以确定它是否是图表。
- 如果是图表,请激活底层 Excel 工作表,然后将此底层文件中的 link 更改为新的源。
我注意到link到excel在整体PPT层面上并不存在[viaInfo
],它们是故意linked 到每个图表,以便可以在不访问源 excel 文件.
的情况下编辑演示文稿
代码有效 - 广泛。
有一个持续的错误(code 运行 现在很好),我认为它与网络和内存稳定性有关(在大约 15 个图表后失败),我是希望根据 .
关闭屏幕更新
问题
我访问的所有图表都linked 到其他工作簿。然而,当 Excel 工作簿暴露给 PowerPoint 时,Linksources 不会显示在 Locals
window 中,即使代码处理每个 link(下图显示 link 存在)
我翻转了自动化以从 Excel 访问 PowerPoint 包,结果相同。没有 Linksources.
为什么在使用 Excel 自动化 PowerPoint 时,完整的对象模型在 Locals window 中也不可用?
这是我偶然发现的局部故障,还是更广泛的问题?
下图显示了遍历 link 的代码(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 RSM submissions May 2016 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
Locals 和 Watch windows 显示对象的属性。可以找到 Workbook 对象的属性列表 here。
LinkSources 是一种带有可选 Type
参数的方法。
如果你想调试 LinkSources
你可以将它添加到 Watch window:
或将 return 值保存到局部变体变量以在 Locals window.
中查看它
背景
我是 运行 代码(来自 PowerPoint):
- 循环浏览演示文稿中的每张幻灯片。
- 检查每个形状以确定它是否是图表。
- 如果是图表,请激活底层 Excel 工作表,然后将此底层文件中的 link 更改为新的源。
我注意到link到excel在整体PPT层面上并不存在[viaInfo
],它们是故意linked 到每个图表,以便可以在不访问源 excel 文件.
代码有效 - 广泛。
有一个持续的错误(code 运行 现在很好),我认为它与网络和内存稳定性有关(在大约 15 个图表后失败),我是希望根据
问题
我访问的所有图表都linked 到其他工作簿。然而,当 Excel 工作簿暴露给 PowerPoint 时,Linksources 不会显示在 Locals
window 中,即使代码处理每个 link(下图显示 link 存在)
我翻转了自动化以从 Excel 访问 PowerPoint 包,结果相同。没有 Linksources.
为什么在使用 Excel 自动化 PowerPoint 时,完整的对象模型在 Locals window 中也不可用?
这是我偶然发现的局部故障,还是更广泛的问题?
下图显示了遍历 link 的代码(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 RSM submissions May 2016 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
Locals 和 Watch windows 显示对象的属性。可以找到 Workbook 对象的属性列表 here。
LinkSources 是一种带有可选 Type
参数的方法。
如果你想调试 LinkSources
你可以将它添加到 Watch window:
或将 return 值保存到局部变体变量以在 Locals window.
中查看它