How to Change PowerPoint SmartArt Text Box Color Based on Text Using VBA
Question details
The user needs a VBA macro that can search for target phrases within longer text across multiple slides and change the fill color of the corresponding SmartArt text boxes.

- Product
- Microsoft PowerPoint
- Device & OS
- not provided
- Scenario
- Automating the formatting of nested SmartArt diagrams across an entire presentation based on the text content inside each shape.
- Observed behavior
- Current macro attempts only work for exact word matches rather than finding specific phrases within longer text, and may struggle with processing deeply nested SmartArt shapes across multiple slides.
Ensure you have the Developer tab enabled in PowerPoint and save a backup of your presentation as a Macro-Enabled Presentation (.pptm) before testing new VBA code.
Use InStr for Partial Text Matching and Consult VBA Specialists
Because SmartArt structures can be deeply nested, you will need a VBA script that iterates through all nodes and uses the InStr function to find specific phrases, though highly complex diagrams may require tailored code from VBA communities.
SmartArt objects in PowerPoint are treated as grouped shapes with nested nodes. To change a color based on partial text, standard equality checks (e.g., Text = "Keyword") will fail if the text box contains a longer sentence.
By utilizing the InStr function, you can search for a substring within the full text of each SmartArt node. If you encounter errors due to diagram complexity, reaching out to specialized VBA forums is highly recommended.
Write an outer loop in your VBA macro to iterate through each 'Slide' in 'ActivePresentation.Slides', and an inner loop to process each 'Shape' on the current slide.
Inside the shape loop, check if the shape contains a SmartArt diagram by evaluating 'If Shape.HasSmartArt = msoTrue'. If it does, create a third loop to iterate through 'Shape.SmartArt.AllNodes' to access every individual text box.
Instead of checking for exact matches, use the InStr function to search for your target phrase within the node's text. For example: 'If InStr(1, Node.TextFrame2.TextRange.Text, "YourTargetPhrase", vbTextCompare) > 0 Then'.
If the InStr function returns a value greater than 0 (meaning the text was found), change the background color of that specific node using 'Node.Shapes(1).Fill.ForeColor.RGB = RGB(255, 0, 0)' (adjusting the RGB values to your desired color).
If your SmartArt contains complex grouping or the code fails to process every slide, post your draft macro and sample SmartArt structure in Microsoft Q&A or Stack Overflow. Include your target phrases and expected colors so a VBA specialist can refine your text-search solution.

Try WPS Office for Your Presentation Needs
If you are struggling with complex Microsoft PowerPoint VBA macros or formatting challenges, consider switching to WPS Presentation. It provides an intuitive interface, rich built-in diagram templates, and powerful formatting tools that make editing effortless without needing to write code.

Frequently Asked Questions
How do I search for a partial word in PowerPoint VBA?
You can use the built-in 'InStr' function in VBA. It returns the position of the first occurrence of one string within another. If the result is greater than 0, it means your target phrase is contained within the text box.
Why isn't my VBA macro changing the color of all nested SmartArt shapes?
SmartArt diagrams often contain nested nodes that aren't accessed by standard shape loops. You must explicitly loop through the 'SmartArt.AllNodes' collection to ensure every sub-level text box is evaluated by your code.
Where is the best place to get help with advanced PowerPoint macros?
For highly specific VBA issues, forums like Stack Overflow (using the 'powerpoint' and 'vba' tags) or the official Microsoft Q&A community are the best places to get tailored code solutions from specialists.




