Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Searching Subfolders for .htm files

Hello

I have a parent folder called MySite. There are child folders within
it. I want to search through VBA the parent folder and all subfolders
for any .htm file. Then each .htm file is searched for any reference
of an 'href' tag. For some reason I can only get it to pull the one
file from the parent site C:\MySite\. My code is below

Any suggestions please?

Thanks
Mark

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

myPath = "C:\MySite\"
workfile = Dir(myPath & "*.htm")

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", 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()
Loop

Set fs = Application.FileSearch
With fs
.LookIn = "C:\MySite"
.Filename = "*.*"
.SearchSubFolders = True
'.FileType = mosFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
'MsgBox .FoundFiles(i)
Next i

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

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Searching Subfolders for .htm files

I've been told filesearch dows has bugs and there is a limit somewhere around
2000 files that it can return. Filesearch doesn't work in 2007. I have 2003
and the code seems to work. The sort order is not b y directory. The sort
is just the basic filename (shortname) without any directory. maybe you are
expecting the directory name to be part of the search.

"Mark" wrote:

Hello

I have a parent folder called MySite. There are child folders within
it. I want to search through VBA the parent folder and all subfolders
for any .htm file. Then each .htm file is searched for any reference
of an 'href' tag. For some reason I can only get it to pull the one
file from the parent site C:\MySite\. My code is below

Any suggestions please?

Thanks
Mark

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

myPath = "C:\MySite\"
workfile = Dir(myPath & "*.htm")

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", 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()
Loop

Set fs = Application.FileSearch
With fs
.LookIn = "C:\MySite"
.Filename = "*.*"
.SearchSubFolders = True
'.FileType = mosFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
'MsgBox .FoundFiles(i)
Next i

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

End Sub

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
Searching through Subfolders Mark[_66_] Excel Programming 2 April 15th 08 10:36 PM
Open all files in subfolders linglc Excel Programming 4 August 19th 06 10:33 AM
Map/List of folders, subfolders & files Bogdan Excel Programming 5 June 11th 06 06:01 PM
copy subfolders, replace text in files and save files in copied subfolders pieros Excel Programming 0 November 1st 05 12:08 PM
Modify - look at files within subfolders Steph[_3_] Excel Programming 1 October 8th 04 06:51 PM


All times are GMT +1. The time now is 06:10 AM.

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"