user8781547
user8781547

Reputation: 1

out.Slides.InsertFromFile f, out.Slides.Count

Getting a runtime error Slides.InsertFromFile : Failed on the excel vba code below. Code worked fine in Office 2010, but 2013 has bought new challenges.

The code works fine until it comes time to save the 0.ppt to the folder location.

Any help is appreciated.


Sub MrgeWC()
Const PPTMERGE_LOCATION = "C:\x\x2\0.ppt"
Const PPTMERGE_FOLDER = "C:\x\x2"


Dim Application
Set Application = CreateObject("Powerpoint.Application")
Application.Visible = True

Dim First
First = True

Set fs = CreateObject("Scripting.FileSystemObject")
Dim Folder
Set Folder = fs.Getfolder(PPTMERGE_FOLDER)

Dim out

Dim ff
For Each ff In Folder.Files
'msgbox ff.Name
f = PPTMERGE_FOLDER + "\" + ff.Name
If First Then
  Dim p
  Set out = Application.Presentations.Open(f)
  out.SaveAs PPTMERGE_LOCATION
  First = False
Else
 out.Slides.InsertFromFile f, out.Slides.Count
 End If
 Next
 If Not First Then
 out.Save
 out.Close
 End If
 Set Folder = Nothing
 Set out = Nothing
 Set Folder = Nothing
 Application.Quit
 Set Application = Nothing

Upvotes: 0

Views: 135

Answers (1)

Mrsryle
Mrsryle

Reputation: 11

We have the same problem and found it to be the inclusion of hidden files ( specifially thumbs.db) into the merge process.

To address we added a simple check to exclude thumbs.db the added line is If NOT ff.Name = "Thumbs.db" Then......

For Each ff in folder.Files
    MsgBox ff.Name
    f = PPTMERGE_FOLDER + "\" + ff.Name
    If first Then
        Dim p
        Set out = Application.Presentations.Open(f)
        out.SaveAs PPTMERGE_FOLDER + "\..\" + PPTMERGE_FILE
        first = False
        Else
        If NOT ff.Name = "Thumbs.db" Then
                out.Slides.InsertFromFile f, out.slides.Count
        End If

        End If
    Next

Upvotes: 1

Related Questions