我有一个PowerPoint,其中包含来自多个Excel电子表格的链接。我想用宏更新链接的对象。 下面的宏将生成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
答案 0 :(得分:0)
此代码阻止了以下警报的发生
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