Search and copy a shape from another file using C#

Joined
May 28, 2010
Messages
1
Reaction score
0
Hi Folks,

I'm fairly new to VS 2010 C# environment for office development.

In PowerPoint 2010, I'm trying to search for a shape available, first in the layout, if not available there, then need to search for the same shape in master, and if still not available, would like to get it from a file where I have stored it already.

Please help me fix my code below:



public void btnInsert_Click(object sender, EventArgs e)

{

PPT.Pane CurrentPane;

App = ThisAddIn.PPTApp;

PPT.Shape DummyShape;

string NewName = string.Empty;

PPT.Shape SourceLegend;

PPT.Shape NewLegend;

PPT.Slide ActiveSlide;

PPT.Master CurrentMaster;

string LegendType = string.Empty;

CurrentMaster = App.ActiveWindow.Selection.SlideRange[1].Master;

LegendType = "SquareLegend";

ActiveSlide = App.ActiveWindow.Selection.SlideRange[1];



if (ActiveSlide.CustomLayout.Shapes[LegendType] != null)

{

SourceLegend = ActiveSlide.CustomLayout.Shapes[LegendType];

}

else if (CurrentMaster.Shapes[LegendType] != null)

{

SourceLegend = ActiveSlide.Master.Shapes[LegendType];

MessageBox.Show(SourceLegend.Name); // to check if it copied the correct shape

}

else

{

//Need to bring the shape from the file "c:\templates.pptx"

SourceLegend = null;

}



///Get new name for the shape

DummyShape = getNewShapeName(SourceLegend.AutoShapeType);

NewName = DummyShape.Name;

MessageBox.Show(NewName);

DummyShape.Delete();



SourceLegend.Copy();

App.ActiveWindow.View.Paste();

NewLegend = App.ActiveWindow.Selection.ShapeRange[1];

NewLegend.Name = NewName;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top