private static void SelectOldShapesToAnimate(PowerPointSlide currentSlide, List<PowerPoint.Shape> shapesToUse) { List<PowerPoint.Shape> shapesToDelete = new List<PowerPoint.Shape>(); bool shouldSelect; var shapes = currentSlide.GetShapesOrderedByTimeline(); foreach (var sh in shapes) { shouldSelect = true; //We should not select existing highlight shapes. Instead they should be deleted if (sh.Name.Contains("PPTLabsHighlightBackgroundShape")) { if (userSelection != HighlightBackgroundSelection.kTextSelected) { foreach (PowerPoint.Shape tmp in shapesToUse) { //Each highlight shape stores a tag of the shape it is associated with if (sh.Tags["HighlightBackground"].Equals(tmp.Name)) { shapesToDelete.Add(sh); shouldSelect = false; break; } } } if (shouldSelect) { currentSlide.DeleteShapeAnimations(sh); sh.Select(Office.MsoTriState.msoFalse); } } //Remove existing animations for highlight text as well if (sh.Name.Contains("HighlightTextShape")) currentSlide.DeleteShapeAnimations(sh); } if (shapesToDelete.Count > 0) foreach (PowerPoint.Shape sh in shapesToDelete) sh.Delete(); }