Here's some basic suggestions. You'll have to figure out how to
enter the correct variable values for the text and search strings. And
you'll need to load the Windows Scripting Runtime from the Projects/reference
menu.
Option Explicit
Dim fso As FileSystemObject
Dim strSearch As String
Private Sub cmdFind_Click()
Dim fil As File, ts As TextStream
Set fso = New FileSystemObject
Dim strEnv As String, strLine As String
Dim blnFound As Boolean
strEnv = Environ$("APPDATA")
If fso.FileExists(strEnv & "\Example.pref") Then
Debug.Print "File Exists"
Set fil = fso.GetFile(strEnv & "\Example.pref")
Set ts = fil.OpenAsTextStream(ForReading)
While ts.AtEndOfStream = False
strLine = ts.ReadLine
blnFound = SearchString(strLine, "example")
If blnFound Then
' Complete your query
Exit Sub
End If
Wend
If Not (blnFound) Then
MsgBox "String not found", vbOKOnly, "Status"
Exit Sub
End If
Else
Debug.Print "File does not exist"
End If
End Sub
Private Function SearchString(StringToSearch As String, Criteria As String) As Boolean
Dim lngReturn As Long
lngReturn = InStr(1, StringToSearch, Criteria, vbTextCompare)
If lngReturn > 0 Then
SearchString = True
Else
SearchString = False
End If
End Function