VBA Code: Remove Underlines from Descenders

First a little history — look at our Stop Underlining Your Descenders! article — of course, as per that article you can manually remove underlines from all characters such as g, j, p, q, and y that sport descenders. However, the task of individually selecting characters to remove underlines is fine if you need to do so for an important slide title or just your opening slide.

Remove Underlines from Descenders

What if you want to do the same task for an entire presentation, as shown in just one slide below?

Everything underlined

OK, we understand that no one has a complete presentation full of underlined text — we are just exploring a proof-of-concept here! You’ll soon realize that this is too much work to do! Especially since you can do this task in PowerPoint super-quickly using some simple VBA code, as Steve Rindsberg of PowerPoint FAQ explains.

First you need to know how you can run VBA scripts in PowerPoint — then use this code. Explore the code a bit though since Steve has put in some helpful comments so that you can edit some values as required.

Sub FixAllDescenders()
' Removes underlines from all descenders in the presentation

    Dim oSl As Slide
    Dim oSh As Shape

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If oSh.HasTextFrame Then
                If oSh.TextFrame.HasText Then
                    FixDescenders oSh
                End If
            End If
        Next
    Next

End Sub

Sub FixDescenders(oSh As Shape)
' Removes underlines from descenders in just the current shape

    Dim x As Long
    Dim oChar As TextRange
    With oSh
    If .HasTextFrame Then
    If .TextFrame.HasText Then
      For x = 1 To Len(.TextFrame.TextRange.Text)
        If IsDescender(Mid$(.TextFrame.TextRange.Text, x, 1)) Then
          .TextFrame.TextRange.Characters(x, 1).Font.Underline = False
        End If
      Next
    End If
    End If
    End With
End Sub

Function IsDescender(sCharacter As String) As Boolean
    Dim sDescenders as String
    sDescenders = "gjpqy"
    If InStr(sDescenders, sCharacter) > 1 Then
        IsDescender = True
    Else
        IsDescender = False
    End If
End Function

Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint window. Before you proceed further, it’s a great idea to save your file — be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then of course the code to remove underlines from descenders will not work! See our PowerPoint File Formats page to learn about these file formats.

Then open or switch to the presentation with the underlined text and run the macro. To do that, press the Alt+F8 shortcut key. In the Macro dialog box that appears, next to Macro in: choose All open presentations, as shown in the figure below. Click the FixAllDescenders Macro name, and then click the Run button.

The code looks at underlined text throughout your presentation, and removes underlines from characters that have descenders. In fact Steve made the code flexible enough so that you could add exceptions or include some other characters too! This code is also available on Steve’s site — and he will update it as required.

Look at the figure below to see the same slide we explored earlier on this page — the slide below has underlines removed from characters with descenders.

Everything underlined

Thank you so much, Steve.

We tested this code using PowerPoint 2010 for Windows. Also, we have not checked this on PowerPoint 2013 for Windows (or 2011 for Mac) — if you do, and it does work or not — then we request you leave a comment below this post and share your thoughts. Of course you should share your thoughts even if you are a Windows user.

Steve RindsbergSteve Rindsberg has been associated with PowerPoint since the product originated more than two decades ago — his PowerPoint FAQ site is a treasure trove of PowerPoint information.

When he’s not updating his site, he’s working on his popular PPTools add-ins for PowerPoint. Steve’s also into a lot of print technology related stuff.


VBA Code: Change Embedded Videos to Linked?

PowerPoint Random Number GeneratorHave you created a huge monster PowerPoint file that’s hundreds of megabytes in size or even a gigabyte? The culprit may be any videos you have inserted on your slides! In years gone by, I always recommended that users place their videos (or any other media or linked files) in the same folder as their PowerPoint presentations so that the links to video files worked when you moved the presentation to another computer. You could then just copy the entire folder to another computer!

PowerPoint 2010 changed everything! Rather than linking videos, the default option was now to embed the videos as part of your PowerPoint file. And that’s how it has been for subsequent releases of PowerPoint, including version 2011 on Mac, and version 2013 on Windows.

Undeniably, this had its share of advantages — no more missing videos, and you no longer need to create a folder. Yes, that’s less housekeeping for you to do, but housekeeping does have its own share of benefits. For one, you don’t end up with huge monster files!

Ideally, you can just delete all the video files, and then insert them again — this time, you can opt to link files rather than embedding them. To do that, click the down arrow next to the Insert button, and you’ll find an option to link rather than embed. Yes, I know that’s not too obvious!

But what if you did not want to re-insert videos all over again? Then just copy all the videos to the same folder as your PowerPoint file, and then run this EmbeddedMoviesToLinkedMovies VBA snippet, graciously coded by Steve Rindsberg of PowerPoint FAQ. Thanks to Steve for allowing us to reproduce this code here. Steve adds that it’s best that you do this only with a copy of your original file.

First you need to know how you can run VBA scripts in PowerPoint — then use this code. Explore the code a bit though since Steve has put in some helpful comments so that you can edit some values as required. Most importantly, be sure to edit the path as directed in the comments, else this code won’t work.

You can actually create a blank, new presentation and insert this code within the VBA editor. To learn how you bring up the VBA editor and add code, look at our VBA scripts in PowerPoint tutorial. Yes, it’s not necessary that this code is placed in the same presentation as your embedded videos — all you need to do is make sure that both presentations (the presentation with this code, and the presentation with the video clips) are open at the same time.

Sub EmbeddedMoviesToLinkedMovies()

Dim oSl As Slide
Dim oSh As Shape
Dim x As Long
Dim sPath As String

' Edit this to the path where vids are stored,
' path must end in backslash
sPath = "C:StuffMovieStuffThisProjectsMovieStuff"

For Each oSl In ActivePresentation.Slides
    For x = oSl.Shapes.Count To 1 Step -1
        Set oSh = oSl.Shapes(x)
        If oSh.Type = msoMedia Then
            If oSh.MediaType = ppMediaTypeMovie Then
                If oSh.MediaFormat.IsEmbedded Then
                    Debug.Print oSh.Name
                    Call ConvertToLinked(oSh, sPath)
                End If
            End If
        End If
    Next    ' Shape
Next    ' Slide

End Sub

Sub ConvertToLinked(oSh As Shape, sPath As String)

Dim oSl As Slide
Dim oNewVid As Shape
Dim x As Long
Dim lZOrder As Long

Set oSl = oSh.Parent
lZOrder = oSh.ZOrderPosition

Set oNewVid = oSl.Shapes.AddMediaObject2(sPath & oSh.Name, msoTrue, msoFalse, _
    oSh.Left, oSh.Top, oSh.Width, oSh.Height)

Do Until oNewVid.ZOrderPosition = lZOrder
    oNewVid.ZOrder (msoSendBackward)
Loop

oSh.Delete
End Sub

Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint window. Before you proceed further, it’s a great idea to save your file — be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then of course the code to change embedded videos to linked will not work! See our PowerPoint File Formats page to learn about these file formats.

Then open or switch to the presentation with the embedded videos and run the macro. To do that, press the Alt+F8 shortcut key. In the Macro dialog box that appears, next to Macro in: choose All open presentations, as shown in the figure below. Click the EmbeddedMoviesToLinkedMovies Macro name, and then click the Run button.

Thank you so much, Steve.

We tested this code using PowerPoint 2010 for Windows. Also, we have not checked this on PowerPoint 2011 for Mac — if you do, and it does work or not — then we request you leave a comment below this post and share your thoughts. Of course you should share your thoughts even if you are a Windows user.

Steve RindsbergSteve Rindsberg has been associated with PowerPoint since the product originated more than two decades ago — his PowerPoint FAQ site is a treasure trove of PowerPoint information.

When he’s not updating his site, he’s working on his popular PPTools add-ins for PowerPoint. Steve’s also into a lot of print technology related stuff.


VBA Code: Remove Animations

Do you want to remove all animations from your slides? You may want to remove animations for a variety of reasons: maybe the sequencing is all messed up, and starting all over again seems like a great idea. But one look at your Animations task pane reveals tens or hundreds of animations on each slide. Is there a magic button somewhere in PowerPoint that can get rid of all animations all together?

Yes, you can do this easily in PowerPoint using some simple VBA code, as John Wilson of PowerPoint Alchemy explains. John adds that this only removes animations from individual slides, and not any animations added within the Slide Master.

First you need to know how you can run VBA scripts in PowerPoint — then use this code. Explore the code a bit though since John has put in some helpful comments so that you can edit some values as required.

Sub Zap_Animations() 
Dim oeff As Effect 
Dim i As Integer 
Dim t As Integer 
Dim osld As Slide 
'Remove normal animations
For Each osld In ActivePresentation.Slides 
For i = osld.TimeLine.MainSequence.Count To 1 Step -1 
osld.TimeLine.MainSequence(i).Delete 
Next i 
'Remove triggers
For i = osld.TimeLine.InteractiveSequences.Count To 1 Step -1 
For t = osld.TimeLine.InteractiveSequences(i).Count To 1 Step -1 
osld.TimeLine.InteractiveSequences(i).Item(t).Delete 
Next t 
Next i 
Next osld 
End Sub 

Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint slides. Before you proceed further, it’s a great idea to save your file — be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension or PowerPoint Macro-Enabled Show with the PPSM extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then of course the Zap_Animations macro will not work! See our PowerPoint File Formats page to learn about these file formats.

Thereafter run the macro — more info can be found in our Use Macros and Scripts in PowerPoint tutorial.

Thank you so much, John.

We tested this code using PowerPoint 2010 for Windows.

John WilsonJohn Wilson is a Microsoft PowerPoint MVP who creates some cool add-ins for PowerPoint.

He participates in the PowerPoint newsgroups and runs the PowerPoint Alchemy site. John is based out of UK, and loves to hear from PowerPoint users about concepts and ideas to create even more PowerPoint add-ins!


VBA Code: Random Number Generator

PowerPoint Random Number GeneratorDo you want a random number generator for your PowerPoint slide? Do you want some numbers from a chosen sequence of numbers to pop up every time you click? Yes, you can do this in PowerPoint using some simple VBA code, as Steve Rindsberg of PowerPoint FAQ explains.

First you need to know how you can run VBA scripts in PowerPoint — then use this code. Explore the code a bit though since Steve has put in some helpful comments so that you can edit some values as required.

Sub UpdateRandomNumber(oSh As Shape)
Dim X as Long
'Make the shape’s text a random number
'X or less
'Change 12 below to any number you’d like:
X = 12

oSh.TextFrame.TextRange.Text = CStr(Random(X))

'Now force PPT to go to the slide again (ie, to redraw it) so that
'the changed text appears:
SlideShowWindows(1).View.GotoSlide (SlideShowWindows(1).View.Slide.SlideIndex)

End Sub

Function Random(High As Long) As Long
'Generates a random number less than or equal to
'the value passed in High
Randomize
Random = Int((High * Rnd) + 1)
End Function

Once you have placed this code in the VBA editor, close the window to get back to your PowerPoint slides. Before you proceed further, it’s a great idea to save your file — be sure to save as a PowerPoint Macro-Enabled Presentation with the PPTM file extension or PowerPoint Macro-Enabled Show with the PPSM extension. If you save as any of the other file formats, PowerPoint will offer to remove the macros, and then of course the Random Number Generator will not work! See our PowerPoint File Formats page to learn about these file formats.

Select any text object such as a text box or even a shape that can fit in a number. Select the text object and format it so that it uses a font size and typeface that you want — you can make these choices even though there’s no actual text in the text object yet.

Now select the text object, and access the Insert tab of the Ribbon. Click the Action button to bring up the Action Settings dialog box. Make sure you are in the Mouse Click tab of this dialog box — now select the Run Macro radio button, and choose the UpdateRandomNumber macro. Click OK, and you are done.

Run the slide in Slide Show view, and click the text object to see a random number.

Thank you so much, Steve.

We tested this code using PowerPoint 2010 for Windows.

Steve RindsbergSteve Rindsberg has been associated with PowerPoint since the product originated more than two decades ago — his PowerPoint FAQ site is a treasure trove of PowerPoint information. When he’s not updating his site, he’s creating new PowerPoint add-ins that expand possibilities within PowerPoint. Steve’s also into a lot of print technology related stuff.


Create Spirographs in PowerPoint Programmatically

Have you created a Spirograph as a child, or even later? If you don’t know what a Spirograph looks like, the picture below may refresh your memory.

Spirographs in PowerPoint

Yes, Spirograph is one of those brands like Xerox that have lesser-known, technical names. Spirographs are essentially Hypotrochoids or Epitrochoids. Even with such such technical words, Spirographs can be fun, especially when you don’t have to draw with ball point pens on paper, and can do it instead on a PowerPoint slide!

You can create Spirograph in PowerPoint quite easily, but it takes time and effort. My friend Shyam Pillai, who is a PowerPoint programming guru stepped in and said I could create Spirographs so much faster programmatically using this code:

Can You Use Scripts in PowerPoint?

If you don’t know how to use macro snippets or scripts inside PowerPoint, look here to get started easily.

  1. Sub CreateSpirograph()
  2. Dim oShp As Shape
  3. Dim I As Single<br />
  4. Const ROTATION_INCREMENT = 5  'Rotation Increment
  5. Const ROTATION_MAX = 360 'Max rotation
  6. 'Select a shape on the slide and then run this
  7. Set oShp = ActiveWindow.Selection.ShapeRange(1)
  8.  
  9. For I = ROTATION_INCREMENT To ROTATION_MAX Step ROTATION_INCREMENT
  10.     With oShp.Duplicate
  11.         .Rotation = I
  12.         .Left = oShp.Left
  13.         .Top = oShp.Top
  14.     End With
  15. Next
  16. End Sub

Remember you need to have some shape selected before you run this code.

You can change the ROTATION_INCREMENT and ROTATION_MAX values to get different graphs for your Spirographs in PowerPoint.


Shyam Pillai is a Microsoft PowerPoint MVP.

His site has many VBA snippets, plus free and commercial PowerPoint add-ins.

Among his well-known add-ins for PowerPoint are Image Importer Wizard, SecurePack, Sequential Save, and Shyam’s Toolbox.


Want to create Spirographs without the programming code? Look at our Spirographs in PowerPoint tutorial.





Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.

Plagiarism will be detected by Copyscape

© 2000-2017, Geetesh Bajaj - All rights reserved.

since November 02, 2000