Quantcast
Channel: General Office Development forum
Viewing all articles
Browse latest Browse all 2257

Cant save powerpoint after deleting links from excel using c#

$
0
0

I am using powerpoint and excel 2010. I have a c# program that opens powerpoint, updates the links from excel, then saves the file as a new filename. I then open the new filename and delete all the links. When I try to save the new filename, I get a COM exception.

Here is the code. Can someone see what i am doing wrong?

Thanks - TFox

namespace A9

  public class UpdatePPLinks

{

  public void DeleteLinks(PowerPoint.Presentation PRS)

{

   foreach(Slide slide in PRs.Slides)

{

    foreach(PowerPoint.Shape shape in slide.Shapes)

    {

       if(shape.Type.Equals(Microsoft.Office.Core.MsoShapeType.msoLinkedOLEObject))

       {

           shape.LinkFormat.BreakLink();

       } 

    }

}

public void init(string sourcefilename, string newfilename)

{

  PowerPoint.Application ppt = new PowerPoint.Application();

  Powerpoint.Presentation PRS = ppt.Presentations.Open(sourcefilename,MsoTriState.False,MsoTriState.False,MsoTriState.True);

  PRS.UpdateLinks();

  PRS.SaveAs(newfilename);

  PRS.Close();

  ppt.Quit();

// Next, we want to delete all the links in the powerpoint file and save it with now links

 

  PowerPoint.Application pp1t = new PowerPoint.Application();

  Powerpoint.Presentation new_PRS = ppt.Presentations.Open(newfilename,MsoTriState.False,MsoTriState.False,MsoTriState.True);

  DeleteLinks(new_PRS);

   new_PRS.Save(); // This is where I get the "Error HRESULT E_FAIL has been returned fro a call to a COM component

  new_PRS.Close();

  ppt1.Quit();

}


Viewing all articles
Browse latest Browse all 2257

Trending Articles