Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- ' ============================================================
- ' PowerPoint Add-In: Select All Shapes with Matching Line Color
- ' ============================================================
- ' This macro selects all shapes on the current slide that have the same
- ' line color as the initially selected shape. It supports both straight
- ' lines and open curved shapes (like arcs or freeforms).
- '
- ' ------------------------------------------------------------
- ' HOW TO USE:
- ' ------------------------------------------------------------
- ' 1️⃣ Select any shape with a visible line color on the slide.
- ' 2️⃣ Run this macro (`ALT + F8`, select "SelectMatchingShapesAll", then "Run").
- ' 3️⃣ The macro will select all other shapes with the same line color.
- '
- ' 💡 Notes:
- ' - If no shape is selected, the macro will show a warning.
- ' - Grouped objects and placeholders are ignored.
- ' - Works for both straight lines (`msoLine`) and open freeform shapes (`msoFreeform`).
- '
- ' ============================================================
- Sub SelectMatchingShapesAll()
- Dim oSelectedShape As Shape
- Dim oSh As Shape
- ' Check if a shape is selected
- If ActiveWindow.Selection.Type <> ppSelectionShapes Then
- MsgBox "Please select a shape before running the macro!", vbExclamation
- Exit Sub
- End If
- ' Store reference shape
- Set oSelectedShape = ActiveWindow.Selection.ShapeRange(1)
- ' Ensure the reference shape has a visible line
- If oSelectedShape.Line.Visible <> msoTrue Then
- MsgBox "The selected object does not have a visible line!", vbExclamation
- Exit Sub
- End If
- ' Ensure the line color is an RGB value
- If oSelectedShape.Line.ForeColor.Type <> msoColorTypeRGB Then
- MsgBox "The line color of the selected shape is not an RGB color! This macro only works with pure RGB colors.", vbExclamation
- Exit Sub
- End If
- ' Loop through all shapes on the slide
- For Each oSh In oSelectedShape.Parent.Shapes
- ' Skip the original selected shape
- If Not oSh Is oSelectedShape Then
- ' Ignore groups & placeholders
- If oSh.Type = msoGroup Or oSh.Type = msoPlaceholder Then GoTo NextShape
- ' Ensure the shape has a visible line
- If oSh.Line.Visible = msoTrue Then
- ' Check if the line color is an RGB value
- If oSh.Line.ForeColor.Type = msoColorTypeRGB Then
- ' If the line colors match → select the shape
- If oSh.Line.ForeColor.RGB = oSelectedShape.Line.ForeColor.RGB Then
- oSh.Select (False)
- End If
- End If
- End If
- End If
- NextShape:
- Next oSh
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement