Select Page

We recently read a question in LinkedIn that related to protecting the privacy of chart based data in PowerPoint presentations:

Is there a macro or some other option that quickly goes in and removes all of the data while leaving the charts and graphs visually intact without degrading the image quality?

 

Manual Answer

Jodi (thanks for the question) wanted to remove all editable data from charts within a PowerPoint file but maintain the high quality of the chart illustration. We can manually do this by copying the chart to the clipboard before deleting it and then using the Paste Special command to paste it back as a vector image using one of the metafile formats. We don’t use PNG or JPG as these are raster (bitmap) formats that suffer from loss of quality when they are scaled.

Once pasted back to the slide, the metafile may be ungrouped to a Microsoft Office drawing object where each individual shape may then be edited in terms of size, color and effects.

Automating the Process

The macro below performs the above automatically to either charts on non-hidden slides only or to charts on all slides within a presentation based on your choice so if you want to prevent a particular chart from being irreversibly converted to an image, just right-click on a slide in the thumbnail pane and select Hide Slide before running the macro.

'----------------------------------------------------------------------------------
' Copyright (c) 2014 YOUpresent Ltd.
' Source code is provide under Creative Commons Attribution License
' This means you must give credit for our original creation in the following form:
' "Includes code created by YOUpresent Ltd. (youpresent.co.uk)"
' Commons Deed @ http://creativecommons.org/licenses/by/3.0/
' License Legal @ http://creativecommons.org/licenses/by/3.0/legalcode
'----------------------------------------------------------------------------------
' Macro to replace all charts across a presentation with a scalable
' vector based image of the chart using the enhanced metafile format.
'
' Processes all charts on all slides, based on user selection of
' slide visibility
'
' Written By : Jamie Garroch
' Date : 15th January 2014
' Website : http://youpresent.co.uk and http://www.gmark.co
'
' Updated 31 January 2014 as follows:
' - Bug Fix : Now switches window views to each slide
' - Enhancement : Now finds charts in and out of placeholders
' - Enhancement : Now processes charts that are within a group (by ungrouping first!)
' - Enhancement : Now reports how many charts were processed
' - Enhancement : Now gives the option to process non-hidden slides only
' - Enhancement : Now saves and restores the user's view
' - Enhancement : Now applies the position of the chart to the pasted picture
' - Enhancement : Now sends the pasted picture to the back layer
'----------------------------------------------------------------------------------

Option Explicit

Private ChartsProcessed As Integer
Private ProcessAll As VbMsgBoxResult
Private Const MacroName = "Automation Macro by GMARK (youpresent.co.uk)"

Public Sub ConvertChartsToVectorImages()
  Dim oSld As Slide
  Dim oShp As Shape
  Dim ShapeCounter As Integer
  Dim SavedView As PpViewType

  ' Ask the user if they want to process all slides or only visible ones
  ProcessAll = MsgBox("Process all slides or only those that are not hidden?" & _
    vbCrLf & vbCrLf & "Yes = All Slides, No = Only Slides Not Hidden", _
    vbQuestion + vbYesNoCancel, MacroName)
  If ProcessAll = vbCancel Then Exit Sub

  ' Save the user's current view (ppViewNormal = 9)
  SavedView = ActiveWindow.ViewType

  For Each oSld In ActivePresentation.Slides
    ' Switch the active view to the next slide in the deck
    ActiveWindow.View.GotoSlide oSld.SlideIndex
    ActiveWindow.ViewType = ppViewSlide
    DoEvents
    If Not (ProcessAll = vbNo And oSld.SlideShowTransition.Hidden = msoTrue) Then
      ' Search each shape on the current slide
SearchShapes:
      For Each oShp In oSld.Shapes
        Debug.Print oShp.Name
        ' If the shape isn't a group and has a chart in it then call the replace function
        If Not oShp.Type = msoGroup And oShp.HasChart Then
          ReplaceChart oSld, oShp
          ' Restart the search because the order of the shapes collection has changed
          ' otherwise multiple charts on a slide will not be processed
          GoTo SearchShapes
        ' If the shape is a group, ungroup it and then start the shape search from scratch on this slide
        ElseIf oShp.Type = msoGroup Then
          oShp.Ungroup
          GoTo SearchShapes
        End If
      Next
    End If
  Next

  ' Switch back to the users view
  ActiveWindow.ViewType = SavedView

  ' Feedback for the user
  If ChartsProcessed = 0 Then
    MsgBox ChartsProcessed & " charts were converted.", _
      vbInformation + vbOKOnly, MacroName
  Else
    MsgBox ChartsProcessed & " charts were converted to scalable vector pictures." & vbCrLf & vbCrLf & _
      "All chart data has been removed (Click OK and Ctrl+Z to undo)", _
      vbInformation + vbOKOnly, MacroName
    ' Reset the counter
    ChartsProcessed = 0
  End If
End Sub

' Copy the shape the clipboard, delete it and then paste it back as a vector image
Private Function ReplaceChart(oSld As Slide, oShp As Shape)
  Dim shpTop As Single
  Dim shpleft As Single

  ' Save the chart position
  shpTop = oShp.Top
  shpleft = oShp.Left

  ' Copy, delete and paste the shape back as a picture
  oShp.Copy
  oShp.Delete
  ActiveWindow.View.PasteSpecial ppPasteEnhancedMetafile

  ' Get a reference to the new picture which will be the last shape in the shapes collection
  Set oShp = oSld.Shapes(oSld.Shapes.Count)

  ' Restore the chart picture position
  oShp.Top = shpTop
  oShp.Left = shpleft

  ' Send the picture to the back layer
  oShp.ZOrder msoSendToBack
  
  ' Increment the counter
  ChartsProcessed = ChartsProcessed + 1
End Function

How To Use

To add our ConvertChartsToVectorImages macro, follow these steps:

  1. Open the presentation in which you want to change the fonts to use your theme
  2. Press Alt+F11 to open the VBE (Visual Basic Editor)*
  3. Right click on your presentation (you should see it in the top left of the VBE)
  4. Hover over Insert and then click Module
  5. Copy the macro code at the end of this post into the module window:
    Replace_Text_With_Lorem_VBE_Macro_PowerPoint
  6. Close the VBE window
  7. Back in your presentation, press Alt+F8 and you will see a window containing the macro which you can select before clicking Run.

License

The code is provided at no cost under the terms of the Creative Commons Attribution license which means you must attribute the work to us. You may do this on one of two ways:

  1. Copy the code below and include the opening copyright section comments
  2. Include the following text and link on at least one slide within your presentation and/or web page where the content resides:Macro design from youpresent.co.uk by GMARK