logo
search
VBA & Macro Problems

How to Find Underlined Text and Apply a Shadow Using PowerPoint VBA

Emma BrownEmma Brown Oct 20, 2026 868 views

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.

How to Find Underlined Text and Apply a Shadow Using PowerPoint 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in PowerPoint.

2
Insert a New Module

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.

3
Paste the Macro Code

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

4
Run the Macro

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.

Use the TextFrame2 Object to Find and Format Underlined Text
TextRange2 Limitation: The property 'Font.Shadow = True' is not valid for the newer TextRange2 object. You must explicitly use the shadow style property (e.g., '.Font.Shadow.Style = msoShadowStyleOuterShadow').
Free Microsoft Office alternative

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.

Fully compatible with Microsoft PowerPoint (.ppt, .pptx) formatsLightweight software that runs smoothly on older devicesRich library of free, professionally designed presentation templatesIntuitive user interface for quick and easy text formatting without coding
microsoft office alternative - wps office

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.