Couple of issues in PowerPoint 2007

Couple of issues in PowerPoint 2007

  • Comments 3

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.

 



 

 

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

Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
  • PingBack from http://microsoftnews.askpcdoc.com/?p=4001

  • hi,

    I figured out another workaround for the problem without using a 'hack' for use with VSTO in .Net.

    it looks like 'the bug' is causing the GradientStops[i] to return only the reference to the first item in the list.

    the trick is, to loop through the collection, and then remove the first item, and append it again at the end of the list.

    this way each GradientStop in the list will become the first item once during looping.

    At the end of the loop, all items are again in the correct order.

    hope this helps :-)

    ps, i noticed that the color is not stored as RGB as you would expect, but in BGR order.

    Great job man!

  • I had the same problem with the RulerLevels collection - I was really grateful to find this post, but I couldn't use the solution above on the collection (am I missing something which would allow me to cycle the collection? I'm new to C#. The collection only implements IEnumerable I think).

    Anyway, I've got round it by temporarily making a fresh copy of the shape with the text box for each RulerLevel I want to get the value of.

    A refinement of Herre's diagnosis of the bug above, at least as far as RulerLevels goes - it's the first item *accessed* that sticks, not necessarily the first in the list.

Page 1 of 1 (3 items)