Select Page

Have you ever been frustrated when trying to select multiple shapes (or objects) on a PowerPoint slide?

Sometimes, it’s just because you have them overlapping on different layers and using the mouse to click is tricky, often leading you to select things you don’t want.

Other times, it’s because you have many copies of a certain shape.

Let’s Look at an Example

In the slide below, we can see that the map of the UK is made up of many freeform shapes for the landmass, around 70 textbox labels and a few callout lines.  The text labels are a bit small so what if we’d like to select them all and increase the font size?

youpresent.co.uk - PowerPoint search and select macro - slide A

What a nightmare! Especially if the map below it is separate shapes (as they’d get selected too).

But, using our macro, it takes around 5 seconds.

Firstly, you need to turn the PowerPoint Selection Pane on. To do this from the PowerPoint ribbon, click Home / Select / Selection Pane.  Now we can see the names of all of our shapes on the slide over there on the right hand side:

youpresent.co.uk - PowerPoint search and select macro - slide B

We can then see that all of the text labels include the common text “Label”.  So let’s run our macro by pressing Alt+F8, selecting it and clicking Run:

youpresent.co.uk - PowerPoint search and select macro - Alt+F8

We’re first asked to enter the text we want to search for within the name of each shape on the current slide:

youpresent.co.uk - PowerPoint search and select macro - string

Once we’ve entered our search text, we click OK and in the blink of an eye (yes, really)…

youpresent.co.uk - PowerPoint search and select macro - result

And hey presto, all our shapes that include the text “label” within their names are selected on the slide:

youpresent.co.uk - PowerPoint search and select macro - slide C

Note that the text box on the top left has also been selected so we can remove that from my selection either by using the Selection Pane and while holding the Ctrl key, clicking it’s name or, we can again hold the Ctrl key while clicking the unwanted shape on the slide.

Now that everything is selected, I could group it all for future use and then modify it’s style such as font size, fill color, glow etc.

Need Your Own Macro or Add-In?

This code is contained within a presentation but it could be a permanent button in the ribbon if we built it into an add-in.  If you need custom macro code or an add-in developed to make your presentation day more productive, contact us now.

Contact Us Now!


How To Use This Macro

To use the code below:

  1. Select all of the code and Copy to your clipboard
  2. Start PowerPoint and Open your presentation
  3. Press Alt+F11 to open the VB Editor
  4. Right-click on the VBAProject in the top left of the window
  5. Select Insert and then Module
  6. Paste the code into the editor window and close the VB Editor (Alt+F4)
  7. Select the slide that you want to search and select shapes
  8. Press Alt+F8 and select SearchAndSelectShapes and follow the instructions

Tip: You can select a shape on the slide and use it’s name as the shape to search for.

VBA Macro Code for PowerPoint

' ================================================================================
' Procedure to find and select similarly named shapes on a selected slide
' Copyright (c) 2013 YOUpresent Ltd. http://www.gmark.co/
' 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
' ================================================================================
 
Public Sub SearchAndSelectShapes()
Dim response As String, search As String, shapeName As String
Dim curSlide As Integer, counter As Integer, foundSpace As Integer
Dim oShp As Shape
 
' Set up error handling
On Error Resume Next
 
' Check the current selection and act accordingly
Select Case ActiveWindow.Selection.Type
	' One or more shapes are selected, check if the user wants to retain the selection and set the counter if yes
	Case ppSelectionShapes
		response = MsgBox("There are one or more shapes selected already." & Chr(13) & Chr(13) & _
		"What do you want to do?" & Chr(13) & Chr(13) & _
		"Yes to include this in your selection" & Chr(13) & _
		"No to find similarly named shapes automatically" & Chr(13) & _
		"Cancel to clear the selection", _
		vbQuestion + vbYesNoCancel, "Selection exists")
		
	Select Case response
		Case vbYes
			counter = ActiveWindow.Selection.ShapeRange.Count
		Case vbNo
			' Get the name of the first selected shape
			shapeName = ActiveWindow.Selection.ShapeRange(1).Name
			' To automatically search, we need to find the first part of the shape name
			' as PowerPoint shapes are named by default using the form "rectangle 123"
			' so let's try to find the first space character
			foundSpace = InStr(1, ActiveWindow.Selection.ShapeRange(1).Name, " ", vbTextCompare)
			' If we found a space, set the search string to the first word of the name
			' and if not, just use the full shape name
			If foundSpace > 0 Then
				search = Left(shapeName, foundSpace - 1)
			Else
				search = shapeName
			End If
			' If we've extracted a search string then skip past asking the user for one
			If Not search = "" Then GoTo skipSearchInput
		Case vbCancel
			ActiveWindow.Selection.Unselect
	End Select
	
	' One or more slides are selected, warn if more than one is selected
	Case ppSelectionSlides
		If ActiveWindow.Selection.SlideRange.Count > 1 Then
			MsgBox "slide selected"
			Exit Sub
		End If
	
	' Nothing is selected so remind the user that a slide must be selected first
	Case ppSelectionNone
		' Check that a slide is in view, if not, an error will occur which we can handle
		curSlide = ActiveWindow.View.Slide.SlideIndex
		If Err.Number <> 0 Then
			MsgBox "Please select a slide first!", vbCritical + vbOKOnly, "No slide selected"
			Exit Sub
		End If
		' Text is selected so unselect it

	Case ppSelectionText
		ActiveWindow.Selection.Unselect
	End Select
	 
	' Ask the user what to search for
	search = InputBox("Enter text to search for in your shape names" & Chr(13) & Chr(13) & _
	"(search is not case sensitive)", "Select Shapes by youpresent.co.uk", "rectangle")
	 
	' Quit  if the user pressed cancel or entered an empty string
	If search = "" Then Exit Sub
 
skipSearchInput:
 
' Get the index of the current slide
curSlide = ActiveWindow.View.Slide.SlideIndex
 
	' Search through all shapes on the slide, looking for the user entered string
	For Each oShp In ActivePresentation.Slides(curSlide).Shapes
		If InStr(1, oShp.Name, search, vbTextCompare) > 0 Then
			' If a corresponding shape is found, add it to the current selection
			oShp.Select msoFalse
			' Increment the counter
			counter = counter + 1
		End If
	Next
 
	' Provide feedback to the user
	Select Case counter
		Case 0
			MsgBox "Search : " & search & Chr(13) & Chr(13) & _
			"Sorry, no shapes matching your search criteria were found.", _
			vbInformation + vbOKOnly, "Select Shapes by youpresent.co.uk"
		Case 1
			MsgBox "Search : " & search & Chr(13) & Chr(13) & _
			counter & " shape was found and is selected on your slide.", _
			vbInformation + vbOKOnly, "Select Shapes by youpresent.co.uk"
		Case Else
			MsgBox "Search : " & search & Chr(13) & Chr(13) & _
			counter & " shapes were found and are selected on your slide.", _
			vbInformation + vbOKOnly, "Select Shapes by youpresent.co.uk"
	End Select
End Sub