I'm somewhat of a rookie when it comes to VBA code, but I'm trying to write code that will search my hard drive for sensitive data, such as social security numbers. I've tried the code below with some very strange results. Is my problem with the wildcard characters or is it something else. I've tried a variety of wildcard characters, but I just can't get the correct result. I'm trying to find the SSN in the typical SSN format; ie. 000-00-0000. Any help would be aprreciated.
Sub searchSSN()
Dim i As Long
Dim fs, f
Dim y()
Set fs = CreateObject("Scripting.FileSystemObject")
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.Filename = "*.*"
.MatchTextExactly = True
.TextOrProperty = "\d{3}-\d{2}-\d{4}"
.MatchAllWordForms = False
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
ReDim y(1 To .FoundFiles.Count, 1 To 7)
For i = 1 To .FoundFiles.Count
Set f = fs.GetFile(.FoundFiles(i))
y(i, 1) = f.Name
y(i, 2) = f.ParentFolder
y(i, 3) = f.DateCreated
y(i, 4) = f.DateLastAccessed
y(i, 5) = f.DateLastModified
y(i, 6) = f.Size
y(i, 7) = f.Type
Next i
Else
MsgBox "There were no files found."
Exit Sub
End If
End With
With Sheets("sheet1")
.[A1:G1] = [{"Name","Folder","Created","Accessed","Modified","Size","Type"}]
.Rows(1).Font.Bold = True
.[A2].Resize(UBound(y, 1), UBound(y, 2)) = y
.Columns.AutoFit
End With
End Sub