Is there a VBA equivalent of MS Office Recolor bitmap image feature?

Bryce Bassett
Bryce Bassett used Ask the Experts™
I'm looking for the VBA equivalent of the Picture Tools, Format, Color, Recolor feature in MS Office.  This is available via the contextual ribbon menu (I'm working in PowerPoint) when you select a bitmap image.  Embedded below is a sample bitmap from our corporate icon library.  The color splash behind the black drawing recolors beautifully to any color you choose using the above feature.  clock icon green iconEverything I have read online suggests that Microsoft did not expose this method for direct manipulation in VBA.  I hope the posts are mistaken!

Does anybody know how to accomplish this?  Is this method maybe available in newer versions of Office? (I currently use 2010 but will be upgrading soon to 2016)  Or does anybody know of a robust workaround?  Assuming the icons are all like the ones above, consisting of black, one color, or transparent, I might be able to use getpixel and setpixel to do it the hard way if necessary.  I've read about those but have no experience using them.

Thanks for any suggestions!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I join to the question!
Senior Technical Consultant at BrightCarbon
I'm using the latest version of 2016 and the object model (F2 in VBE) doesn't appear to support recolor as these are the only properties available for the .PictureFormat object:

.ColorType (with options to change to B&W, greyscale, watermark
.Crop (several properties)

Open in new window

So, the next port of call was to check if there is any idMso that could be used:

Application.CommandBars.ExecuteMso "control ID string"

for example:

Application.CommandBars.ExecuteMso "PictureCorrectionsDialog"

Open in new window

I checked the control ID list for PowerPoint 2016 and didn't find anything.

The last option is to try to mirror the user behaviour with SendKeys but this is always "dodgy" in practice. This is the keystroke sequence that will recolour to Accent 1:


This is it in code:

Sub RecolorAccent1()
 SendKeys "%", True ' Alt
 SendKeys "J", True ' J+P = Contextual Picture Tools / Format
 SendKeys "P", True
 SendKeys "I", True ' Color
 Exit Sub ' because the following cause a long delay due to Live Preview
 SendKeys "{DOWN}", True ' Down three times to reach Recolor
 SendKeys "{DOWN}", True
 SendKeys "{DOWN}", True
 SendKeys "{RIGHT}", True ' Right to select Accent 1
 SendKeys "{ENTER}", True ' Enter to select
End Sub

Open in new window

But I couldn't get this to work reliably due to the varying times PowerPoint takes to create the live preview when navigating the Color effect gallery.

However, returning to what you want to do, if you want the ability to recolour corporate graphical assets, why not create the library as scalable and editable EPS files instead of fixed raster files, import them, ungroup them to convert to native PowerPoint vectors and then you can recolour them as required, assigning all kinds of macro automation to change the colours of specific elements within the graphic group? This is a rough run at this task but given you have the source files for the graphic, you could create a group that had a single element for the icon and a single element for the splash (unlike my multiple freeform objects):

icon converted to EPS, imported, ungrouped, renamed, reordered and regrouped
Note too that from October last year, PowerPoint 2016 also supports SVG which is great for icons. One thing many Adobe designers of icons don't understand about PowerPoint is that the quality is degraded if the user scales the icon or doesn't have the file set to be saved with high resolution. They also don't seem to realise that Powerpoint supports vector graphics and that this gives the best editable and scalable options. However, if a brand team doesn't want icons to be recoloured, that may be a reason for issuing them in a raster format, even if PowerPoint can circumvent that to a degree.

Finally, I had another idea. You "could" keep an internal copy of recoloured shapes, either on the slide or hidden away in a master custom layout somewhere and pickup the format from the one you want and apply it to the selected shape. If I select two copies of your icon on a slide, the first of which has been recoloured, this will pickup that format and apply it to the second selected shape:


Open in new window

Bryce BassettFreelance VBA programmer



Thanks for your very thorough analysis of the options!  Confirms what I had read, that there isn't a direct way to recolor in VBA.  

I love your solution for using the source .EPS files to create PowerPoint vectors that can be recolored.  Our design group works on Macs (of course) and has deliberately deployed the icon library as .PNGs in the past, in three different color schemes to match our three corporate divisions.  But they realize that's three times the work, and hard to keep in synch, so I'm sure they will be open to this solution.  Let me work with them and report back before I close the question, but I think this is my answer.  Thanks!
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Bryce BassettFreelance VBA programmer


Based on Jamie's suggestion, I've written up a test routine for identifying and converting the color of the swoosh.  I converted the original EPS and re-saved as EMF because I need to have these icons living as external files in a content library.  The code below imports the EMF (of course this would be a more elaborate file picker), ungroups it, finds the color swoosh, and recolors it.  The one part that feels a bit contrived is having to re-find the ungrouped shape.  Is there a more elegant way to do that?  Or any other improvements you would suggest to streamline this code?  Thanks for your help.

Sub recolorswoosh()

Dim x As Integer
Dim iconpicked As String
Dim myshape As Shape
Dim currentslide As Slide
Dim refindleft As Single
Dim refindtop As Single
Dim myMSshape As Shape
Dim farthestleft As Single
Dim myswoosh As Shape

iconpicked = "C:\Test\nuclear.emf"

Set currentslide = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)
Set myshape = currentslide.Shapes.AddPicture(FileName:=iconpicked, linktofile:=msoFalse, _
        savewithdocument:=msoTrue, Left:=200, Top:=200)
findleft = myshape.Left 'store left edge of imported EMF so we can refind it later
findtop = myshape.Top 'store top edge of imported EMF so we can refind it later

myshape.Ungroup 'convert EMF to Microsoft Office drawing object so we can manipulate it

'find the converted shape by matching stored coordinates
For Each myshape In currentslide.Shapes
    If myshape.Left = findleft And myshape.Top = findtop Then
        Set myMSshape = myshape
        Exit For
    End If

'the left most shape will be the swoosh in every case.  Iterate the shapes to identify it.
farthestleft = 1200
For x = 1 To myMSshape.GroupItems.count
    Set myshape = myMSshape.GroupItems(x)
    If myshape.Left < farthestleft Then
        Set myswoosh = myshape
        farthestleft = myshape.Left
    End If
Next x

MsgBox "The swoosh is named " & myswoosh.Name & vbCrLf & " located at left = " & myswoosh.Left & vbCrLf & " filled with color " & myswoosh.Fill.ForeColor

myswoosh.Fill.ForeColor.RGB = RGB(255, 0, 0)

End Sub

Open in new window

File attached.
Jamie GarrochSenior Technical Consultant at BrightCarbon

Hi versatilebb. I believe the original question has been answered and this is now a new question about managing EMF groups. To keep EE 'clean' I would suggest closing this question and opening a new question so the answer to this new question can be easily found. There are several suggestions I can make for you.
Bryce BassettFreelance VBA programmer


Thanks for your help.  The EPS import and vector shapes method works great.  Transferring to a new question on that topic

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial