I'm trying to copy each slide from a presentation and save each slide in it's own ppt-file. This is my code (I know this is not VBA, but I'm hoping you can help regardless):
function exportSingleSlides(pathname, filename){ var app = new ActiveXObject("PowerPoint.Application");
app.Visible = true;
// Open the presentation
var presentation = app.Presentations.Open(pathname+filename, true);
var tmpPresentation; // Used to store a new presentation for each slide.
var e = new Enumerator(presentation.Slides);
var slide;
e.moveFirst();
var i = 0;
while (!e.atEnd()) {
i++;
slide = e.item(); // gets this slide
// Export slide to png
slide.Export(pathname + 'slide' + (i < 10 ? '0' + i : i) + '.png', 'PNG', 1920, 1080);
// Open new presentation
tmpPresentation = app.Presentations.Add();
// Set up the slide size to be the same as the source.
tmpPresentation.PageSetup.SlideHeight = presentation.PageSetup.SlideHeight;
tmpPresentation.PageSetup.SlideWidth = presentation.PageSetup.SlideWidth;
// Get the layout from the source slide
layout = slide.CustomLayout;
// Copy current slide and paste into new presentation
slide.Copy();
tmpPresentation.Slides.Paste(1);
// Set the layout
tmpPresentation.Slides(1).CustomLayout = layout;
// Save and close
tmpPresentation.SaveAs(pathname + 'slide' + (i < 10 ? '0' + i : i));
tmpPresentation.Close();
e.moveNext();
}
// Close the presentation. (But how do I close powerpoint entirely?)
presentation.Close();
app.Quit();
}
// Which file are we looking at?
var pathname = 'C:\\Users\\Stian\\Dropbox\\jobb\\RB\\powerpoint parser\\';
var filename = 'test.pptx';
exportSingleSlides(pathname, filename);
Running this gives me a "Unspecified error" at tmpPresentation.SaveAs(). And that's odd, because it works as it should if I remove the line that sets CustomLayout = layout. Help?