Couple of issues in PowerPoint 2007

One of my customer reported a couple of very interesting issues (bugs?) in PowerPoint 2007.

If you have a presentation which has a shape with a gradient and you try to find out the color of each gradient using GradientStops.Color.RGB from .NET, you might get incorrect results. You can also reproduce this issue from VBA with the following steps.

1) Create a new presentation with a single slide.
2) Delete textboxes and anything else that's present on the slide.
3) Click on Insert->Shapes, select rectangle.
4) Right click on the shape, select "Format Shape"
5) Click on gradient fill and click close.
6) Hit Alt+F11 to go to VBA editer, if immediate window is not visible, hit Ctrl+G to make it visible.
7) If watch window is not visible make it visible by clicking on View -> "Watch window"
8) Now, in the immediate window try "?Application.ActivePresentation.Slides(1).Shapes(1).Fill.GradientStops(1).Color"
9) Try this for all the gradients, YOU WILL GET DIFFERENT VALUES - EXPECTED RESULT
10) Drag-n-Drop "Application.ActivePresentation.Slides(1).Shapes(1).Fill.GradientStops(1).Color" to the watch window (note:don't select "?" while drag-drop)
11) Modify the immediate window to "?Application.ActivePresentation.Slides(1).Shapes(1).Fill.GradientStops(2).Color" (changed 1 to 2)
12) Now drag-drop this statement (except "?") to watch window.
13) Do this for all the gradients, YOU WILL SEE SAME VALUE FOR ALL THE GRADIENTS - UNEXPECTED
14) Now, try steps (8) and (9) again, this time YOU WILL SEE SAME VALUE FOR ALL THE GRADIENTS - UNEXPECTED

The same issue also reproduces with "RulerLevels" collection

After some troubleshooting I found out that using Application.ActivePresentation.Slides(n).Shapes(n).Fill.GradientStops(n).Color.RGB gives correct values when you use it from VBA macro.

Well , after finding this, I did the obvious fwd these issues to the bug database and the so that the concerned teams can take it from here (dev/test etc.)

Now,  what can you do right now, especially  if you are programming in .NET. How does this finding helps you? It does, if you don't mind a bit patchy solution (Okay .. a workaround if I must say ). You can simply put a small macro in an PPA or PPAM addin (something like ...)

 Public Function getGradientStopColor(ByVal iSlide As Integer, ByVal iShape As Integer, ByVal iGS As Integer) As Long
      getGradientStopColor = ActivePresentation.Slides(iSlide).Shapes(iShape).Fill.GradientStops(iGS).Color.RGB
End Function

And call the macro from you .NET code, something like this ...

 object[] oParam = { 1, 1, 1 };
object retVal = Globals.ThisAddIn.Application.Run("getGradientStopColor", ref oParam);
Debug.WriteLine(retVal.ToString());

oParam[0] = 1; oParam[1] = 1; oParam[2] = 2;
retVal = Globals.ThisAddIn.Application.Run("getGradientStopColor", ref oParam);
Debug.WriteLine(retVal.ToString());

oParam[0] = 1; oParam[1] = 1; oParam[2] = 3;
retVal = Globals.ThisAddIn.Application.Run("getGradientStopColor", ref oParam);
Debug.WriteLine(retVal.ToString());

Hold on ..I know, not a great way of doing things, but unfortunately I didn't find anything better.

If you do find something better, please keep me posted.

 

del.icio.us tags: Pranav+Wagh, Microsoft+Blogger, Office+2007, Office2007, PowerPoint, Code+Snippet

Technorati tags: Pranav+Wagh, Microsoft+Blogger, Office+2007, Office2007, PowerPoint, Code+Snippet

 

 

Not responsible for errors in content, meaning, tact, or judgment. Live and let live. Toes go in first. I didn't do it. Enjoy.