Results 1 to 14 of 14

VBScript.RegExp

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    VBScript.RegExp

    a week ago I asked an Excel programming question related to searching for a particular string. Leith Ross provided a solution based on RegExp. I am trying to use this method now for a PowerPoint macro.

    I used a PowerPoint macro that I use to remove carriage returns from a textbox and merged in the RegExp code. The result can be seen below.

    With this sub I am getting an Object required error message for the replace statement. I have no idea how to code this part correctly. Does anybody know how to debug this line.

    Sub DeleteBracketsAndContents()
        Dim oshp As Shape
        Dim otxt As TextRange
         
        Set RegExp = CreateObject("VBScript.RegExp")
        RegExp.IgnoreCase = True
        RegExp.Pattern = "[[]\number.*[]]"
         
         'check for type of selection 
         'replaces all text in shape unless text is highlighted
        If ActiveWindow.Selection.Type = ppSelectionNone _
        Or ActiveWindow.Selection.Type = ppSelectionSlides Then Exit Sub
        If ActiveWindow.Selection.Type = ppSelectionShapes Then
            Set oshp = ActiveWindow.Selection.ShapeRange(1)
            Set otxt = oshp.TextFrame.TextRange
        End If
        If ActiveWindow.Selection.Type = ppSelectionText Then
            Set otxt = ActiveWindow.Selection.TextRange
            If Len(otxt) < 1 Then
                Set otxt = otxt.Parent.Parent.TextFrame.TextRange
            End If
        End If
        
        'Replace text
        With otxt
                  '    .Text = Replace(.Text, vbCr, " ")  
                  '    The above line removes carriage returns in my PowerPoint macro
                  '     I replaced vbCr with Reg.Pattern. It was a wild guess.
              .Text = Replace(.Text, Reg.Pattern, "")         
        End With
        
        Set RegExp = Nothing
        
    End Sub
    Last edited by dschmitt; 06-23-2010 at 08:47 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1