PDA

View Full Version : SaveAs giving "Unspecified error"



L42
04-03-2014, 01:47 AM
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?

John Wilson
04-04-2014, 07:47 AM
I'm not a C# person but if you are running in 2010 or later there is a new method .PublishSlides which publishes your presentation as a series of single slide presentations. Although it is intended for SharePoint it works with a local path as long as the original is already saved.

http://msdn.microsoft.com/en-us/library/ff744375%28v=office.14%29.aspx