Error when saving PowerPoint file using VBA from within Excel

baldgit

New Member
Joined
May 23, 2016
Messages
4
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?

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,215,103
Messages
6,123,108
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top