Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I want to search a given text file for a certain string. Is this possible?
If so, how would I code it? The file path and name is stored in the variable Filename. The search text is "NODE DATA" I just want excel to search the file given and return a boolean (True/False) as to whether the string exists in the text file. All help is appreciated. Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As usual, it's not until after you post your question that you stumble onto
the solution... With Application.FileSearch .NewSearch .LookIn = Filename .SearchSubFolders = True .TextOrProperty = "NODE DATA" .FileType = msoFileTypeAllFiles If .Execute 0 Then ...some code End if End With "crazybass2" wrote: I want to search a given text file for a certain string. Is this possible? If so, how would I code it? The file path and name is stored in the variable Filename. The search text is "NODE DATA" I just want excel to search the file given and return a boolean (True/False) as to whether the string exists in the text file. All help is appreciated. Thanks. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe this is faster and it doesn't need an extra reference:
Function CheckForStringInFile(strString As String, _ strFile As String) As Boolean 'result will be True if string is in the file 'and False if the string is missing 'because of vbBinaryCompare this will be case sensitive '------------------------------------------------------ Dim hFile As Long Dim buff As String On Error GoTo ERROROUT 'obtain file handle, open file 'and load into a string buffer hFile = FreeFile Open strFile For Input As #hFile buff = Input$(LOF(hFile), hFile) Close #hFile If InStr(1, buff, strString, vbBinaryCompare) = 0 Then CheckForStringInFile = False Else CheckForStringInFile = True End If Exit Function ERROROUT: On Error GoTo 0 End Function RBS "crazybass2" wrote in message ... As usual, it's not until after you post your question that you stumble onto the solution... With Application.FileSearch .NewSearch .LookIn = Filename .SearchSubFolders = True .TextOrProperty = "NODE DATA" .FileType = msoFileTypeAllFiles If .Execute 0 Then ...some code End if End With "crazybass2" wrote: I want to search a given text file for a certain string. Is this possible? If so, how would I code it? The file path and name is stored in the variable Filename. The search text is "NODE DATA" I just want excel to search the file given and return a boolean (True/False) as to whether the string exists in the text file. All help is appreciated. Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Search If on text string | Excel Worksheet Functions | |||
search text string for number | Excel Discussion (Misc queries) | |||
Nested formula to search a text string and return specific text | Excel Worksheet Functions | |||
Search for a text string | Excel Discussion (Misc queries) | |||
Search, find or lookup defined text in text string | Excel Worksheet Functions |