Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default opening and searching files in filesearch

Hello

I have a filesearch.application running in my code that works fine. I
need to somehow within that code, open each file that it finds, search
it for a reference, and then if found print the enite line into
excel. I have the following code that give me errors on the open
part.

myPath = "C:\Exelon\"
workfile = Dir(myPath & "*.html")

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Exelon"
.Filename = ".html"
.SearchSubFolders = True
'.FileType = mosFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
Open myPath & workfile For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If InStr(1, WholeLine, "href", vbTextCompare) 0 Then
myR = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(myR, 1).Value = workfile
Cells(myR, 2).Value = WholeLine
End If
Wend
Close #1
workfile = Dir()

MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count

Next i

Else
MsgBox "There were no files found."
End If
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default opening and searching files in filesearch

You don't have any looping - the code that I posted will work

Sub CheckTextFilesForHREFs()
Dim WholeLine As String
Dim myPath As String
Dim workfile As String
Dim myR As Long

myPath = "C:\Excel\Text Files\"
workfile = Dir(myPath & "*.html")

Do While workfile < ""
Open myPath & workfile For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If InStr(1, WholeLine, "href") 0 Then
myR = Cells(Rows.Count,1).End(xlUp).Row + 1
Cells(myR,1).Value = workfile
Cells(myR,2).Value = WholeLine
End If
Wend
Close #1
workfile = Dir()
Loop

End Sub



--
HTH,
Bernie
MS Excel MVP


"Mark" wrote in message
...
Hello

I have a filesearch.application running in my code that works fine. I
need to somehow within that code, open each file that it finds, search
it for a reference, and then if found print the enite line into
excel. I have the following code that give me errors on the open
part.

myPath = "C:\Exelon\"
workfile = Dir(myPath & "*.html")

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Exelon"
.Filename = ".html"
.SearchSubFolders = True
'.FileType = mosFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
Open myPath & workfile For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If InStr(1, WholeLine, "href", vbTextCompare) 0 Then
myR = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(myR, 1).Value = workfile
Cells(myR, 2).Value = WholeLine
End If
Wend
Close #1
workfile = Dir()

MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count

Next i

Else
MsgBox "There were no files found."
End If
End With



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filesearch not finding files Kevin Excel Programming 1 January 18th 05 01:49 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 4 September 1st 03 08:50 PM
FileSearch doesn't find zip files Hub van de Laar Excel Programming 3 September 1st 03 07:43 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 0 September 1st 03 06:53 PM
FileSearch dislikes Zip-files Hub van de Laar Excel Programming 0 September 1st 03 06:52 PM


All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"