Powerpoint VBA: Clear all formatting from a string

Posted on 2005-04-21
Last Modified: 2012-05-05
Excel has a great WorksheetFunction called .clean which strips all nonprintable characters from a string.  Does Powerpoint have anything comparable, or can you suggest a macro that will do this in Powerpoint XP (i.e., vbTab, vbCrLf, etc)?
Question by:lpupa
    LVL 6

    Accepted Solution

    Add this function to a module in VBA :

    Public Function Clean(ByVal sString As String) As String
      Dim iChar As Integer
      Dim iCode As Integer
      Clean = ""
      For iChar = 1 To Len(sString)
        iCode = Asc(Mid$(sString, iChar, 1))
        If iCode >= 32 And iCode <= 126 Then Clean = Clean + Chr$(iCode)
      Next iChar
    End Function

    You can then test it with :

    Public Sub Test()
      sString = Clean("ABC" & vbTab & vbCrLf & "ETR")
      ' sString now contains only "ABCETR"
    End Sub


    Author Comment

    Testing this little function head to head with calling Excel from Powerpoint, both "cleaned" the string text equally well.
    The function ran in 1/10 the time it took to automate Excel and run WorksheetFunction.Clean.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now