logo
search
VBA & Macro Problems

How to Change PowerPoint SmartArt Text Box Color Based on Text Using VBA

Amos GikundaAmos Gikunda Oct 7, 2026 868 views

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.

Change PowerPoint SmartArt Text Box Color Based on Text Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Set up the slide and shape loops

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.

2
Identify SmartArt objects and nodes

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.

3
Use InStr for phrase searching

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'.

4
Apply the new fill color

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).

5
Post in a specialized community for complex layouts

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.

Use InStr for Partial Text Matching and Consult VBA Specialists
Important Context for VBA Forums: When asking for help online, always specify whether your code needs to process every slide and deeply nested shapes, as this drastically changes how the VBA loops must be written.
Free Microsoft Office alternative

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.

High compatibility with Microsoft PowerPoint (.ppt and .pptx) formatsRich library of built-in SmartArt-like diagrams and professional templatesUser-friendly interface that makes manual formatting fast and easyLightweight, fast, and free to download
microsoft office alternative - wps office

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.