View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Opening Text Files Through Notebook

Mark,

The sub below will search all files in the specified folder for the word href. It will write the
filenames and lines out to the active worksheet.

HTH,
Bernie
MS Excel MVP

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 & "*.txt")

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


"Mark" wrote in message
...
Hello all

Was hoping someone could help with this. Not really familiar with VBA
or sure if this is possible. Within VBA I wanted to open Notebook the
application, and then open a text file in Notebook. I will eventually
want to loop through all .txt files within the specified folder and
search for href tags. All these .txt files are source code files for
a website, and I'm trying to search for 3rd party websites. So
essentially...I want to open Notebook, open the first file, search the
file for href tags, close the file, open the next...

Any help would be really great! thanks!