Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
Sub SearchTextFile()
     Const strFileName = "C:\test.txt"
     Const strSearch = "TEST"
     Dim strLine As String
     Dim f As Integer
     Dim lngLine As Long
     Dim blnFound As Boolean
     f = FreeFile
     Open strFileName For Input As #f
     Do While Not EOF(f)
         lngLine = lngLine + 1
         Line Input #f, strLine
         If InStr(1, strLine, strSearch, vbBinaryCompare) > 0 Then
             MsgBox "Search string found in line " & lngLine, vbInformation
             blnFound = True
             Exit Do
         End If
     Loop
     Close #f
     If Not blnFound Then
         MsgBox "Search string not found", vbInformation
     End If
 End Sub


  • No labels