Question

Raman Sethi on Wed, 24 Jul 2013 05:14:16


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Powerpoint = Microsoft.Office.Interop.PowerPoint;

using Office = Microsoft.Office.Core;

namespace Powerpoint_Aspect_Ratio

{

    class Program

    {      

        static void Main(string[] args)

        {

            Powerpoint.Application oAppPowerpoint;

            Powerpoint.Presentation objPres;

            Powerpoint.Presentation objPres1;

            try

            {

                oAppPowerpoint = new Powerpoint.Application();

                Powerpoint.Presentations ppPrens = oAppPowerpoint.Presentations;

                string filename = @"C:\ppttest\16.pptx";

                objPres = ppPrens.Open(filename, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);

                int slidecount = objPres.Slides.Count;

                int i = 0;

                foreach (Powerpoint.Slide slide in objPres.Slides)

                {

                    slide.Copy();

                    Powerpoint.Presentations ppPrens1 = oAppPowerpoint.Presentations;

                    string filename1 = @"C:\ppttest\test.pptx";

                    objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);

                    int tempslidecount = objPres1.Slides.Count;

                    Powerpoint.Slides pasteSlides = objPres1.Slides;

                    pasteSlides.Paste(-1);

                    objPres1.Save();

                }

                objPres.Close();

                oAppPowerpoint.Quit();

            }

            catch (Exception ex)

            {

            }

        }

    }

}

Note: The sample works fine in Office 2010 but not in Office2013.

Exception occurs for office 2013:

Message = "Slides (unknown member): Invalid request.  Clipboard is empty or contains data which may not be pasted here."

Replies

Raman Sethi on Wed, 24 Jul 2013 11:14:25


In addition to what I posted above if we try it the way i have posted in this comment the powerpointslide is copied to the temporary slide but when I copy it from the temporary slide to a new slide named "test" here it again fails.The clipboard is still empty.Can someone please also explain if you are able to find the issue with this code that why is clipboard empty and how to copy data(ppt) from that.

using System;
using Powerpoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Powerpoint.Application oAppPowerpoint;
Powerpoint.Presentation objPres;
Powerpoint.Presentation objPres1;
try
{
oAppPowerpoint = new Powerpoint.Application();
Powerpoint.Presentations ppPrens = oAppPowerpoint.Presentations;
string filename = @"C:\ppttest\16.pptx";
objPres = ppPrens.Open(filename, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
int slidecount = objPres.Slides.Count;
foreach (Powerpoint.Slide slide in objPres.Slides)
{                                        
//slide.Copy();
string tempfilename = @"C:\ppttest\temp";
slide.Export(tempfilename,"ppt",800,600);
Powerpoint.Presentations ppPrens1 = oAppPowerpoint.Presentations;
string filename1 = @"C:\ppttest\test.pptx";
objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
int tempslidecount = objPres1.Slides.Count;
Powerpoint.Slides pasteSlides = objPres1.Slides;
//pasteSlides.Paste(-1);
pasteSlides.InsertFromFile(tempfilename+".ppt",0,1,-1);
objPres1.Save();

}
objPres.Close();
oAppPowerpoint.Quit();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}

                    

Raman Sethi on Wed, 24 Jul 2013 11:22:48


While using office 2013 and trying to copy paste the slides using Interop the paste fails.I've also tried Export and InsertFromFile but the error displayed is  Slides (unknown member): Invalid request.  Clipboard is empty or contains data which may not be pasted here." 

Can someone explain the right process or how to copy from clipboard.I'll post the copde if needed.

Yuri Macrovsky on Tue, 30 Jul 2013 07:49:19


clipboard is not trustworthy. Consider OpenXML SDK.

achir.shi on Sat, 19 Dec 2015 15:38:51


I'm experiencing exactly the same problem.

My solution is create the new presentation WITH WINDOW.
Change following line 
objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
into
objPres1 = ppPrens1.Open(filename1, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);

fix this problem.

Good luck!

Saurabh Singh Jadon on Wed, 27 Dec 2017 12:35:33


Thanks Achir.

It solves my problem.