How to Find Underlined Text and Apply a Shadow Using PowerPoint VBA
Question details
Automate the process of finding single-underlined text in a PowerPoint presentation and applying a text shadow effect to those specific words using VBA.

- Product
- PowerPoint
- Device & OS
- not provided
- Scenario
- A user needs to apply a specific shadow style to all text that currently has a single underline across multiple slides, avoiding manual formatting.
- Observed behavior
- Because underlining is a font-level format rather than a paragraph format, a macro must inspect each word individually. Attempting to use the standard Font.Shadow boolean property on TextRange2 results in an error.
Ensure that the Developer tab is enabled in your PowerPoint ribbon and save your presentation as a Macro-Enabled Presentation (.pptm) before running any scripts to prevent code loss.
Use the TextFrame2 Object to Find and Format Underlined Text
This method uses a VBA macro to loop through a specified range of slides, checks every shape for text, and applies an outer shadow to any word with a single underline.
PowerPoint VBA must inspect text character by character or word by word because underlining is applied through font formatting rather than paragraph formatting. By utilizing the TextFrame2 object, you can accurately target individual words and apply newer shadow styles.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in PowerPoint.
In the Project Explorer pane on the left, right-click your presentation name, select 'Insert', and click 'Module'. A new blank code window will appear.
Copy and paste the following code into the module window: Sub AddShadowToUnderline() Dim slideIndex As Long Dim wordIndex As Long Dim currentShape As Shape ' Adjust the slide range here (e.g., 36 To 37) For slideIndex = 36 To 37 For Each currentShape In ActivePresentation.Slides(slideIndex).Shapes If currentShape.HasTextFrame Then If currentShape.TextFrame2.HasText Then For wordIndex = 1 To currentShape.TextFrame2.TextRange.Words.Count With currentShape.TextFrame2.TextRange.Words(wordIndex) If .Font.UnderlineStyle = msoUnderlineSingleLine Then .Font.Shadow.Style = msoShadowStyleOuterShadow End If End With Next wordIndex End If End If Next currentShape Next slideIndex End Sub
Modify the 'slideIndex = 36 To 37' line to match the slides you want to process (or use '1 To ActivePresentation.Slides.Count' for all slides). Then, press F5 or click the green 'Run' button in the toolbar to execute the macro.

Try WPS Office for Your Presentation Needs
While advanced VBA macros are specific to certain environments, WPS Presentation offers an intuitive, free, and lightweight alternative for creating and designing stunning slides. It provides robust text formatting tools and is fully compatible with Microsoft PowerPoint files.

Frequently Asked Questions
Why do I get an error when using Font.Shadow = True in my PowerPoint macro?
In PowerPoint VBA, when working with the newer TextRange2 object (accessed via TextFrame2), the boolean property '.Shadow = True' is invalid. You must specify the exact shadow style using '.Font.Shadow.Style = msoShadowStyleOuterShadow'.
How can I change the macro to search the entire presentation instead of just slides 36 and 37?
To loop through all slides in the active presentation, replace the line 'For slideIndex = 36 To 37' with 'For slideIndex = 1 To ActivePresentation.Slides.Count'.
Does this VBA macro affect text inside grouped shapes?
The provided basic macro only iterates through top-level shapes on a slide. To check text within grouped shapes, you need to add an additional loop to check 'Shape.GroupItems' or create a recursive function that drills down into grouped objects.
Can I use the older TextRange object instead of TextFrame2?
Yes, if you use the older TextFrame.TextRange object, you can successfully use the 'Font.Shadow = True' property. However, TextFrame2 is generally recommended for modern presentations as it supports advanced typography and newer Office formatting features.




