vba - 在 PowerPoint 中使用 VBA 更新 msoLinkedOLEObject 时如何绕过 Excel 弹出窗口
问题描述
我有一个包含多个 Excel 电子表格链接的 PowerPoint。我想用宏更新链接对象。下面的宏将生成 2 种类型的弹出窗口。在我的情况下,每个链接都会出现弹出窗口以更新大约 30 次。单击取消将允许宏继续。1) Microsoft Excel 已停止工作(关闭程序) 2) 文件正在使用(只读、通知或取消选项)
有没有办法绕过这些消息?
Sub linkupdate()
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoLinkedOLEObject Then
If LCase(oshp.LinkFormat.SourceFullName) Like "*defect 95R*" Then
oshp.LinkFormat.AutoUpdate = ppUpdateOptionManual
oshp.LinkFormat.Update
oshp.LinkFormat.AutoUpdate = ppUpdateOptionAutomatic
End If
End If
Next
Next
MsgBox "Finished updating Charts", , "Update Complete"
End Sub
解决方案
此代码阻止了以下警报的发生
1) Microsoft Excel 已停止工作(关闭程序)
2) 文件正在使用(只读、通知或取消选项)
完成宏弹出后,用户可能需要一分钟才能控制 PowerPoint。我假设 excel 警报正在后台关闭,因为有超过 30 个链接图表。
我是 VBA 的新手,所以这段代码可能效率不高。
Sub linkUpdate()
Const xFile = "C:\temp\defect 95R.xlsx"
Dim pptPresentation As Presentation
Dim osld As Slide
Dim oshp As PowerPoint.Shape
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
xlApp.Visible = True
xlApp.Workbooks.Open xFile, ReadOnly:=True, Notify:=False
xlApp.Workbooks.Application.DisplayAlerts = False
Set pptPresentation = ActivePresentation
'Loop through each slide in the presentation
For Each osld In pptPresentation.Slides
'Loop through each shape in each slide
For Each oshp In osld.Shapes
'Find out if the shape is a msoLinkedOLEObject type=10
If oshp.Type = msoLinkedOLEObject Then
'Only update shape if file name contains defect 95r
If LCase(oshp.LinkFormat.SourceFullName) Like "*defect 95r*" Then
oshp.LinkFormat.AutoUpdate = ppUpdateOptionManual
xlApp.Workbooks.Application.DisplayAlerts = False
oshp.LinkFormat.Update
oshp.LinkFormat.AutoUpdate = ppUpdateOptionAutomatic
End If
End If
Next
Next
xlApp.Workbooks.Close
xlApp.Workbooks.Application.Quit
Set xlApp = Nothing
MsgBox "Finished updating Charts", , "Update Complete"
End Sub
推荐阅读
- javascript - 自定义路由组件从不匹配确切路径=“/”
- bootstrap-5 - 引导颜色变量
- python - 如何使用 python 脚本中的日期作为参数从命令提示符运行 python 脚本?
- linux - 无法通过 SSH 连接到 Oracle 云实例
- excel - 如何使用 VBA 更改 PPT 中的图表
- python - Python:组合集合和数组
- python - Pandas DataFrame 从另一个 DataFrame 中找到最常见的字符串
- google-bigquery - GA4 事件实时显示,但不在参与/事件中
- html - 如何使用 Bootstrap 更改响应页面上的文本位置?
- html - AllegroServe 的 htmlgen 中的 form、img、span 和 table 标签有什么特别之处?