Advertisement
David-P

Untitled

Feb 6th, 2025
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 2.85 KB | Source Code | 0 0
  1. Option Explicit
  2.  
  3. ' ============================================================
  4. ' PowerPoint Add-In: Select All Shapes with Matching Line Color
  5. ' ============================================================
  6. ' This macro selects all shapes on the current slide that have the same
  7. ' line color as the initially selected shape. It supports both straight
  8. ' lines and open curved shapes (like arcs or freeforms).
  9. '
  10. ' ------------------------------------------------------------
  11. ' HOW TO USE:
  12. ' ------------------------------------------------------------
  13. ' 1️⃣ Select any shape with a visible line color on the slide.
  14. ' 2️⃣ Run this macro (`ALT + F8`, select "SelectMatchingShapesAll", then "Run").
  15. ' 3️⃣ The macro will select all other shapes with the same line color.
  16. '
  17. ' 💡 Notes:
  18. ' - If no shape is selected, the macro will show a warning.
  19. ' - Grouped objects and placeholders are ignored.
  20. ' - Works for both straight lines (`msoLine`) and open freeform shapes (`msoFreeform`).
  21. '
  22. ' ============================================================
  23.  
  24. Sub SelectMatchingShapesAll()
  25.     Dim oSelectedShape As Shape
  26.     Dim oSh As Shape
  27.    
  28.     ' Check if a shape is selected
  29.    If ActiveWindow.Selection.Type <> ppSelectionShapes Then
  30.         MsgBox "Please select a shape before running the macro!", vbExclamation
  31.         Exit Sub
  32.     End If
  33.    
  34.     ' Store reference shape
  35.    Set oSelectedShape = ActiveWindow.Selection.ShapeRange(1)
  36.  
  37.     ' Ensure the reference shape has a visible line
  38.    If oSelectedShape.Line.Visible <> msoTrue Then
  39.         MsgBox "The selected object does not have a visible line!", vbExclamation
  40.         Exit Sub
  41.     End If
  42.  
  43.     ' Ensure the line color is an RGB value
  44.    If oSelectedShape.Line.ForeColor.Type <> msoColorTypeRGB Then
  45.         MsgBox "The line color of the selected shape is not an RGB color! This macro only works with pure RGB colors.", vbExclamation
  46.         Exit Sub
  47.     End If
  48.  
  49.     ' Loop through all shapes on the slide
  50.    For Each oSh In oSelectedShape.Parent.Shapes
  51.         ' Skip the original selected shape
  52.        If Not oSh Is oSelectedShape Then
  53.            
  54.             ' Ignore groups & placeholders
  55.            If oSh.Type = msoGroup Or oSh.Type = msoPlaceholder Then GoTo NextShape
  56.            
  57.             ' Ensure the shape has a visible line
  58.            If oSh.Line.Visible = msoTrue Then
  59.                
  60.                 ' Check if the line color is an RGB value
  61.                If oSh.Line.ForeColor.Type = msoColorTypeRGB Then
  62.                    
  63.                     ' If the line colors match → select the shape
  64.                    If oSh.Line.ForeColor.RGB = oSelectedShape.Line.ForeColor.RGB Then
  65.                         oSh.Select (False)
  66.                     End If
  67.                 End If
  68.             End If
  69.         End If
  70.        
  71. NextShape:
  72.     Next oSh
  73.  
  74. End Sub
Tags: Powerpoint
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement