Maybe you wanted to see if the comments contain the text, and not only find parts where the text is exactly equal to the comments:
Sub FindFilesWithComment()
Dim oComment As String
oComment = "Hello" 'Comment to search for
Dim FolderPath As String
FolderPath = BrowseForFolder()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim oFiles As Object
If FolderPath = "" Then
Exit Sub
End If
Dim oFileNames As String
oFileNames = "Files with comments: " & oComment
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(FolderPath)
For Each oFile In oFolder.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "ipt" Then
Dim oDoc As PartDocument
Set oDoc = ThisApplication.Documents.Open(FolderPath & "\" & oFile.Name, False)
Dim commentVal As String
commentVal = oDoc.PropertySets.Item("Inventor Summary Information").Item("Comments").Value
If InStr(1, commentVal, oComment, vbTextCompare) > 0 Then
oFileNames = oFileNames & vbCrLf & oFile.Name
End If
oDoc.Close
End If
Next oFile
Call MsgBox(oFileNames, , "Found Files")
End Sub
Function BrowseForFolder(Optional OpenAt As Variant) As Variant
Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0
Set ShellApp = Nothing
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select
Exit Function
Invalid:
BrowseForFolder = ""
End Function