Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Regular Expressions in PowerPoint

Working in Europe we often get presentations using the , as a decimal separator 234.72 for example. For UK or US use this needs to be changed to 234.72.

In Word this is possible using the advanced search options available which are based on Regular Expressions but PowerPoint only has a basic Search and replace function. Searching for commas and replacing with full stops (periods) will of course change ALL commas not just those in number.

You could create a complex macro to find strings which are numeric and only do the replace there but it would be time consuming.

Here's How to Use regX in PowerPoint

Don't know how to use code?

Sub use_regex() 
    Dim regX As Object 
    Dim osld As Slide 
    Dim oshp As Shape 
    Dim strInput As String 
    Dim b_found As Boolean 
     
    Set regX = CreateObject("vbscript.regexp") 
    With regX 
        .Global = True 
        .Pattern = "(\d),(\d)" 
    End With 
    For Each osld In ActivePresentation.Slides 
        For Each oshp In osld.Shapes 
            If oshp.HasTextFrame Then 
                If oshp.TextFrame.HasText Then 
                    strInput = oshp.TextFrame.TextRange.Text 
                    b_found = regX.Test(strInput) 
                    If b_found = True Then 
                        strInput = regX.Replace(strInput, "$1.$2") 
                        oshp.TextFrame.TextRange = strInput 
                    End If 
                End If 
            End If 
        Next oshp 
    Next osld 
    Set regX= Nothing 
End Sub 

How Does It work?

First the code loads an instance of RegEx and then loops through the text on each slide.

The Search pattern (\d),(\d) looks for any digit followed by , followed by any digit. The () tells RegEx to stiore the text found in $1 and $2.

The Replace line replaces the found pattern with $1 (the first number . and $2 (the second number)

 

 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation