使用Office 2010套件,我有一个PowerPoint演示文稿,其中所有图表都链接到Excel工作簿。为了将演示文稿和/或工作簿移动到另一个目录,必须更新所有链接以指向新的工作簿位置。为此,我编写了以下代码,该代码驻留在PowerPoint中的标准代码模块中:
Private Sub RedirectLinks()
Dim Source As String
Dim Dest As String
Dim Action As Integer
If InStr(1, ActivePresentation.Path, "Dev\") > 1 Then
Action = MsgBox("Changing pointers to PRODUCTION", vbOKCancel)
Source = "Dev\"
Dest = vbNull
Else
Action = MsgBox("Changing pointers to DEVELOPMENT", vbOKCancel)
Source = "Templates\"
Dest = "Dev\Templates\"
End If
If Action = vbOK Then
Dim SL As Slide
Dim SH As Shape
Dim Top As Double
Dim Left As Double
Dim Width As Double
Dim Height As Double
For Each SL In ActivePresentation.Slides
SL.Select
For Each SH In SL.Shapes
SH.Select
If SH.Type = msoLinkedOLEObject Then 'when we find a linked one
Top = SH.Top
Left = SH.Left
Width = SH.Width
Height = SH.Height
SH.LinkFormat.SourceFullName = Replace(SH.LinkFormat.SourceFullName, Source, Dest)
SH.Top = Top
SH.Left = Left
SH.Height = Height
SH.Width = Width
End If
Next
Next
End If
If InStr(1, Dest, "dev") > 0 Then
Action = MsgBox("About to OVER WRITE the Dev copy with this one." & vbCrLf & "Click 'Cancel' to prevent this and save manually", vbOKCancel, "OVER WRITE WARNING!!")
Else
Action = MsgBox("About to OVER WRITE the PRODUCTION copy with this one." & vbCrLf & "Click 'Cancel' to prevent this and save manually", vbOKCancel, "OVER WRITE WARNING!!")
End If
If Action = vbOK Then
ActivePresentation.SaveAs Replace(ActivePresentation.Path, Source, Dest) & ActivePresentation.Name
End If
End Sub
代码执行得很好但是,我经常在执行SH.LinkFormat.SourceFullName = Replace(SH.LinkFormat.SourceFullName, Source, Dest)
行时从Excel弹出这个消息框。
注意事项:
'another user'
锁定,这实际上是我。我通常可以通过关闭工作簿来获得此警告,然后立即重新打开它。我不知道它是否是网络延迟问题(文件驻留在服务器上,而不是本地),或者是什么,但是在使用工作簿一段时间之后,我将获得{{1消息。workbook is now available for read-write
的行时,每次时都没有收到此警告。有时候我会得到它的次数,有时我根本不会得到它,有时我偶尔会得到它。.SourceFullName
似乎并未改善这种情况。
有没有人对如何解决此问题有任何建议?
答案 0 :(得分:1)
当PPT中的代码打开PPTM并且我的宏安全设置比#34更严格时,我遇到了奇怪的行为。打开任何傻瓜"。尝试在PPT和Excel中尽可能低地拨打您的宏安全性,就像测试一样,看看是否能解决问题。
如果有人知道如何动态设置安全选项并在之后重置它们,那就更好了。在执行任何调用XL的操作之前,可以通过注册表执行此操作。