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.


PowerPoint 2013 for Developers: Conversation with Steve Rindsberg

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.

In this conversation, Steve discusses what the upcoming PowerPoint 2013 offers developers, and about the rumours that apps will replace add-ins soon.

Geetesh: PowerPoint 2013 seems to be adding several new options for developers — can you share some thoughts?

Steve: I am assuming this question is about what is new for developers in PowerPoint 2013, and what can Indezine readers and other PowerPoint users can expect to see in PowerPoint add-ins as a result.

The features that hold the most promise, at least to me, are:

  1. Presentation Broadcasting: Add-ins should be able to launch, pause and resume broadcast presentations and even add meeting notes to the broadcast.
  2. Guides: Developers can now add, delete and position drawing guides. How about an add-in that lets you create a set of guides — and then memorize it. You could then recall it, or any other “guide set” you’ve created, with a click of the mouse?
  3. Commenting: It’s been expanded to allow replying to comments and accessing these replies. I can imagine an add-in that would extract all the comments in a presentation and show them to the user in a more organized way than we now have.
  4. Charting: There are some interesting-looking new features here, but as yet they don’t appear to be “wired up” yet. The new AddChart2 method seems to be better at producing error messages than charts, but I’m hoping that it and the other new features will enable us to add and manipulate charts without Excel flashing in and out of view as currently happens.

There’s a list of the new goodies for developers here: What’s new for PowerPoint 2013 developers, including lots of links to online documentation of new objects, methods and properties; hardly any of these have any useful information yet, but I expect they’ll be fleshed out as the release date gets closer and features are locked in.

Geetesh: What’s all this talk about the new Office apps replacing add-ins? Will add-ins continue to work in PowerPoint 2013?

Steve: When Ms. Foley says “…add-ins are passé. Apps are in.” she’s telling us more about the world Microsoft wants us to move into than the world we’ll actually live in, at least for the next version or two of Office. And for PowerPoint users, the story’s completely different. PowerPoint 2013 doesn’t support the new add-in model Foley writes about. Office apps won’t replace “traditional” PowerPoint add-ins just yet.

The story for traditional add-ins promises to have a happy beginning and ending. I’ve been testing all of my PPTools add-ins in Office 2013 (in the Click To Run version, no less). They all work nicely. In fact, I’ve updated the installers so anyone can test PPTools add-ins while testing the Office 2013 Preview (and report bugs using the Contact link on every page of PPTools.com).

Naturally, I can’t speak for all add-ins, and in fact some of them are almost certain to have issues with the Click To Run version of Office 2013, but Microsoft and the developers will probably sort these out by the time Office 2013 releases.


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.





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