none
Copying slides from another PPT with "keep source formatting" RRS feed

  • Question

  • I have written a C++ Power Point add-in but the problem is not C++ specific. It may be also viewed as VBA or C# issue. One of the things it does is inserting a slide from an external PPT into the current presentation.

    I fail to find the proper way to do it so that the format is preserved. I have used programmatic Copy/Paste approach as well as InsertFromFile() and I am having issues, especially on Power Point 2003 (I want to support 2003 - 2010).

    If I do it manually, I can normally copy the slide, then paste it and finally tick the "Keep Source Formatting". The problem is I do not know how to do that in Power Point 2003. It seems to work in 2010 if I do this:

    m_pPowerPointApplication->CommandBars->ExecuteMso(ATL::CComBSTR("PasteSourceFormatting"));
    

    Is there any way to make this work in Power Point 2003?

    Wednesday, November 9, 2011 10:51 AM

All replies

  • Hello,

    In the object model of PowerPoint 2003, I've found only Paste (or PasteSpecial) option; anything resembling "Keep Source Formatting" or "Use Destination Theme" options is missing.

    I suppose you need to use Slide.ApplyTemplate() after you use Slides.Paste() or Slides.InsertFromFile(). Is this the case?


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Wednesday, November 9, 2011 11:53 AM
  • Hello,

    In the object model of PowerPoint 2003, I've found only Paste (or PasteSpecial) option; anything resembling "Keep Source Formatting" or "Use Destination Theme" options is missing.

    I suppose you need to use Slide.ApplyTemplate() after you use Slides.Paste() or Slides.InsertFromFile(). Is this the case?


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader

    Thanks Andrei,

    Actually, I said I tried InsertFromFile() and it did not help. I have not tried ApplyTemplate() though but just before your answer I have stumbled upon http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/2085dcd1-6977-4bcb-9e74-7f1f49a83d61/ and http://skp.mvps.org/pptxp001.htm and the latter really helped. I did not need the full VB code for my particular scenario, just a few top lines. Here is something that seems to work consistently across Power Point 2003-2010.

    	void Copy(PowerPoint::_SlidePtr slide)
    	{
    		slide->Copy();
    
    		PowerPoint::_SlidePtr newSlide = CConnect::PowerPointPresentation->Slides->Paste(CConnect::PowerPointPresentation->Slides->Count + 1)->Item(_variant_t(1L));
    
    		newSlide->Design = slide->Design;
    		newSlide->ColorScheme = slide->ColorScheme;
    		newSlide->Select();
    	}
    
    

    Of course, one could still use InsertFromFile() if one wanted not to involve clipboard but I really did not want to bother.

    Wednesday, November 9, 2011 3:41 PM
  • Actually, now that I played with it a bit more, the code I posted does not work 100% in all scenarios. I needed to add one more line:

    newSlide->CustomLayout = slide->CustomLayout;
    


    Then the slides are truly inserted with "keep source formatting". Still, life sucks because I get an error message box when I try to save such document: "Microsoft office cannot open this file because some parts are missing or invalid".

    So even though I seem to have found a workaround, I now cannot save the perfect documents I produce. 

    Thursday, November 10, 2011 9:52 AM
  • Hi, how abou the problem on your side? How did you save the document? Could you show us more code snippet? We will try to reproduce the scnario. If you still show any concern on the problem, just feel free to let us know.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, November 14, 2011 6:42 AM
  • Hi Bruce,

    When I said "I try to save" this means I try to save as a user would (Cltr+S). I am not saving programmatically if that is your concern. The entire code snippet would then be like this:

    void Copy(PowerPoint::_SlidePtr slide)
    	{
    		slide->Copy();
    
    		PowerPoint::_SlidePtr newSlide = CConnect::PowerPointPresentation->Slides->Paste(CConnect::PowerPointPresentation->Slides->Count + 1)->Item(_variant_t(1L));
    
    		newSlide->Design = slide->Design;
    		newSlide->ColorScheme = slide->ColorScheme;
    		<strong>newSlide->CustomLayout = slide->CustomLayout;</strong>
    		newSlide->Select();
    	}
    


    Please note the bold line. When this one is commented out the saving works, otherwise it does not. I could try to build a full sample that reproduces the issue but it would take me some time. Let me know if you want me to do this.

    Thanks!

    Monday, November 14, 2011 5:16 PM
  • Wannabe.wpf.dev, I will involve someone who are more farmiliar with the managed C++ to help you. There might be some delay about the response. Appreciate your patience.

    >>I could try to build a full sample that reproduces the issue but it would take me some time. Let me know if you want me to do this.

    It will be nice if you can build a demo sample which can reproduce the issue because this can make us to research and resolve your problem more convenient and quickly.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 15, 2011 2:36 AM
  • Bruce,

    I will build the sample and let you know. Do you want me to attach it here or send somewhere in particular?

    Btw, this is pure C++, not managed C++. Hopefully that will help.

    Thanks!

    Tuesday, November 15, 2011 7:49 AM
  • Hi Wannabe.wpf.dev,

    I know you mentioned it may be also viewed as VBA or C#, could you be able to provide us with a sample of the VBA Code you are using that reproduces the issue?

     

    Best Regards,


    Arthur Ch[MSFT]
    • Proposed as answer by Bruce Song Monday, November 21, 2011 12:49 PM
    • Unproposed as answer by wannabe.wpf.dev Wednesday, November 23, 2011 5:28 PM
    Wednesday, November 16, 2011 11:00 PM
  • Hi again,

    Ok, I finally found time to reproduce this in C# add-in. I did not want to bother with VBA but I assume it is not really that complicated either.

    Please find the project here: https://rapidshare.com/files/4004182818/CustomLayoutPowerPointAddIn.7z

    After you hit "Click Me!" button in the new tab, some sample PPT file I found online will be downloaded to a temp folder and the first slide inserted. All will be well. After you attempt to save the presentation you will get a nasty error I already mentioned.

    Let me know what you think. Thanks!


    Wednesday, November 23, 2011 5:28 PM
  • Is there any progress on this?

    Thanks!

    Thursday, December 1, 2011 10:19 PM
  • I would like to reiterate all the original poster said and resurrect this thread.

    I also have to make presentations using slides from other files.  I am doing this in php using COM.  Luckily the slides i currently have do not need the 'CustomLayout' to be copied over.

    This works:

    //add a slide to the pres from a file
    	function addSlideFromFile($param) {
    		$this->_presentation->Slides->InsertFromFile($param, $this->_presentation->Slides->Count);
    		//apparently the formatting is not copied over, to add insult to injury, the gui has a 
    		//'keep source formatting' checkbox, but is not avail thru api hence the following:
    		$this->copyFormattingFromFile($param);
    	}
    	
    	//copy the formatting to the new slide.
    	function copyFormattingFromFile($param) {
    		//get the files slide
    		$pwpTemp = new COM("powerpoint.application");
    		$pwpTemp->Visible = true;
    		$presOld=$pwpTemp->Presentations->Open($param);
    		
    		$oldSlide = $presOld->Slides[1];
    		$newSlide = $this->_presentation->Slides[$this->_presentation->Slides->Count];
    		
    		$newSlide->Design = $oldSlide->Design;
    		$newSlide->ColorScheme = $oldSlide->ColorScheme;
    		//$newSlide->CustomLayout = $oldSlide->CustomLayout;
    	}
    and then you can call $this->_presentation->SaveAs($param); and all is good:  HOWEVER if you uncomment the line
    //$newSlide->CustomLayout = $oldSlide->CustomLayout;
    the file cannot be saved. 


    jimbit

    Monday, September 3, 2012 12:50 AM
  • There is a hotfix for Office 2007:

    Slide formatting is lost when you use the Slides.InsertFromFile method to insert slides in Office PowerPoint 2007

    http://support.microsoft.com/kb/2433043/en-us

    Monday, April 22, 2013 8:17 PM
  • Slide.ApplyTemplate()

    thanks this worked for me !!!! powerpoint 2016

    Tuesday, January 29, 2019 3:13 PM