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
Bookmarks