Sub use_regex()
Dim regX As Object
Dim oMatch As Object
Dim osld As Slide
Dim oshp As Shape
Dim strInput As String
Dim b_found As Boolean
Dim strReport As String
Dim i As Integer
Dim iFileNum As Integer
Dim b_First As Boolean
Dim b_start As Boolean
Dim strpattern As String
On Error Resume Next
Set regX = CreateObject("vbscript.regexp")
strpattern = "[0-9]{5} [0-9]{6}"
With regX
.Global = True
.Pattern = strpattern
End With
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
strInput = oshp.TextFrame.TextRange.Text
b_found = regX.Test(strInput)
If b_found = True Then
If Not b_start Then
b_start = True
strReport = strReport & "Results" & vbCrLf
End If
strReport = strReport & vbCrLf & "On Slide " & osld.SlideIndex & ": "
Set oMatch = regX.Execute(strInput)
For i = 0 To oMatch.Count - 1
strReport = strReport & oMatch(i) & " / "
Next i
b_First = False
If Right(strReport, 2) = "/ " Then strReport = Left(strReport, Len(strReport) - 2)
End If
End If
End If
Next oshp
Next osld
If strReport = "" Then strReport = "NOT FOUND!"
iFileNum = FreeFile
Open Environ("USERPROFILE") & "\Desktop\Abbr.txt" For Output As iFileNum
Print #iFileNum, strReport
Close iFileNum
Call Shell("NOTEPAD.EXE " & Environ("USERPROFILE") & "\Desktop\Abbr.txt", vbNormalFocus)
Set regX = Nothing
End Sub
The code declares the variables needed including regx as an Object.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented: