How do I resolve the spreadsheet locked for editing error?
Using Office 2010, I have a PowerPoint presentation where all charts are linked to an Excel workbook. To move a presentation and / or workbook to a different directory, all links must be updated to point to the location of the new book. To do this, I wrote the following code, which is located in the standard code module in 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
The code runs just fine, however I often get this message box from Excel when it executes a line SH.LinkFormat.SourceFullName = Replace(SH.LinkFormat.SourceFullName, Source, Dest)
.
Notes:
- Actually this book is closed - I know it hasn't been opened by anyone else (I'm the only one who usually uses it and another person who isn't there in the office this morning).
- It claims the file is locked
'another user'
, which is actually me. I can often get this warning by closing the workbook and then immediately reopening it. I don't know if the problem is caused by network latency (the file is on the server, not locally) or something, but a few seconds after using the workbook I get the messageworkbook is now available for read-write
. - I don't get this warning every time it tries to execute the line that sets
.SourceFullName
. Sometimes I get it most of the time, sometimes I don't get it at all, sometimes I get it sometimes. - Despite my thoughts on network lag, no matter how fast or slow I debug the code, I get this message in random order.
- Marking new or old books as
Read-only
OS level doesn't seem to make things better.- However, tagging both seems to give me 2 warnings for every replacement is done.
Does anyone have any suggestions to fix this?
source to share
I ran into odd behavior where the code in PPT opens PPTM and my Macro security settings is something tighter than "Open any stupid thing". Try typing your PPT and Excel macro protection as low as they will be, just like the test, and see if that fixes the problem.
If anyone knows how to set security parameters on the fly and reset after them, that would be even better. It might be possible to do this through the registry before doing anything that will trigger XL.
source to share