Hi - hoping you can help with an issue with my code. There are numerous posts around this error but they don't seem to be related to the issue I'm having.
I have a Powerpoint file with some slides containing data linked to an Excel workbook. Both are saved on a network drive.
When I run the code below I get error message "Method 'SaveAs' of object '_presentation' failed (Run-time error '-2147467259 (80004005)'), on the "pPreso.SaveAs Saveloc" step. The weird thing is that if I press debug, run-> continue, it saves the file as expected (i.e. it successfully executes this line of code).
I can similarly get round the issue by putting a MSGBOX "OK" box in front of the SaveAs line. However, putting Application.Wait "00:00:05" does not work.
Can anyone point out what the issue is?
I have a Powerpoint file with some slides containing data linked to an Excel workbook. Both are saved on a network drive.
When I run the code below I get error message "Method 'SaveAs' of object '_presentation' failed (Run-time error '-2147467259 (80004005)'), on the "pPreso.SaveAs Saveloc" step. The weird thing is that if I press debug, run-> continue, it saves the file as expected (i.e. it successfully executes this line of code).
I can similarly get round the issue by putting a MSGBOX "OK" box in front of the SaveAs line. However, putting Application.Wait "00:00:05" does not work.
Can anyone point out what the issue is?
Code:
Sub UpdatePPT()
Dim Saveloc As Variant
Saveloc = Application.GetSaveAsFilename(InitialFileName:=Sheets("Employer Data").Range("G2").Value & " Discussion Template", _
FileFilter:="PowerPoint Files (*.pptx), *.pptx")
If Saveloc = False Then Exit Sub
'Open the PowerPoint file
Dim pApp As Object
Dim pPreso As Object
Dim pSlide As Object
Dim sPreso As String
sPreso = "G:\.......\.....\Discussion Template.pptx"
On Error Resume Next
Set pApp = GetObject(, "PowerPoint.Application")
If Err.Number <> 0 Then
Set pApp = CreateObject("PowerPoint.Application")
pApp.Visible = True
End If
On Error Resume Next
Set pPreso = pApp.Presentations(sPreso)
If Err.Number <> 0 Then
Set pPreso = pApp.Presentations.Open(Filename:=sPreso)
End If
'Update the links
On Error GoTo 0
pPreso.UpdateLinks
Application.CalculateUntilAsyncQueriesDone
'Break the links
Dim shp As PowerPoint.Shape
Dim sld As PowerPoint.Slide
For Each sld In pPreso.Slides
For Each shp In sld.Shapes
If shp.Type = msoLinkedOLEObject Then
shp.LinkFormat.BreakLink
End If
Next shp
Next sld
Application.CalculateUntilAsyncQueriesDone
'Save as a new file in the folder selected
pPreso.SaveAs Saveloc
pApp.Quit
End Sub