Now here is an unlikely blog post! Clemens writes VBA snippets for PowerPoint!

There’s one problem that bugs everyone who is doing lots of presentations with PowerPoint at conferences and has to adjust the slides to whatever the respective conference’s PowerPoint template is: Color Schemes. Color Schemes are quite nice when you are in control of whatever your templates are, but if you must comply with someone else’s taste for color combinations or their complete ignorance about the color scheme, you might end up spending hours re-coloring your presentation’s graphics, because whenever you import or copy & paste graphics between presentations, the graphics adopt the destination’s color scheme. Here’s how that might end up looking:

 

Bah! I have tons of very complex graphics with animations that evolve over time (and reuse) and re-coloring the slide I am showing here would take quite a bit of time. And – really – green and light gray on dark gray with light gray text on white isn’t exactly “best practice” when it comes to presentations.   

What causes this is that PowerPoint will, by default, assign the “color scheme index” to the fill and line colors of any shape if you pick the colors from the existing color scheme (and the UI is designed to make you do that). This index information takes precedence over any explicit RGB value set for the shape’s fill or line or text color. So whenever you move the shapes to a different presentation, they will adopt the color scheme setting. Luckily, and that’s something I found out yesterday because I found myself once again in the situation to have to fix a deck, it’s possible to break that link between a shape’s coloring and the color scheme by programmatically modifying the respective ColorFormat element and resetting the SchemeColor so that it doesn’t refer to one of the  preset color scheme “slots”. Below is the resulting VBA macro for PowerPoint (yes, it cost me great pain to go there) that’ll simply replace the color-scheme index information on any drawing shape so that colors of shapes (the macro ignores text) will be completely preserved as you copy stuff between presentations. Put that into the source presentation and run StripSchemeColorFromShapes() once.

Sub StripSchemeColorFromShapes()
    Dim currentShape As Shape
    Dim currentSlide As Slide

    For Each currentSlide In ActivePresentation.Slides
        For Each currentShape In currentSlide.Shapes
        If currentShape.Type = msoGroup Then
            RecolorGroup currentShape.GroupItems
        Else
            RecolorShape currentShape
        End If
        Next currentShape
    Next currentSlide
End Sub

Sub
RecolorGroup(group As GroupShapes)
   Dim currentShape As Shape

   For Each currentShape In group
      If currentShape.Type = msoGroup Then
          RecolorGroup currentShape.GroupItems
       Else
          RecolorShape currentShape
       End If
   Next currentShape
End Sub

Sub RecolorShape(currentShape As Shape)
    Dim clr As ColorFormat

    On Error Resume Next

    If currentShape.Fill.Visible Then
        Set clr = currentShape.Fill.ForeColor
        clr.SchemeColor = ppSchemeColorMixed
        currentShape.Fill.ForeColor = clr
        Set clr = currentShape.Fill.ForeColor
        clr.SchemeColor = ppSchemeColorMixed
        currentShape.Fill.BackColor = clr
    End If

    If currentShape.Line.Visible Then
        Set clr = currentShape.Line.ForeColor
        clr.SchemeColor = ppSchemeColorMixed
        currentShape.Line.ForeColor = clr

        Set clr = currentShape.Line.BackColor
        clr.SchemeColor = ppSchemeColorMixed
        currentShape.Line.BackColor = clr
    End If

   On Error GoTo 0
End Sub


Once I ran the macro in the original presentation, all I had to do was to copy & paste it into the destination and see there! Done:

Updated: