Consulting

Results 1 to 2 of 2

Thread: SaveAs giving "Unspecified error"

  1. #1
    VBAX Newbie
    Joined
    Apr 2014
    Posts
    1
    Location

    SaveAs giving "Unspecified error"

    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?

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    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/libr...ice.14%29.aspx
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •