Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / April 2008

Tip: Looking for answers? Try searching our database.

Opening Text Files Through Notebook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 15 Apr 2008 16:14 GMT
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!
Bernie Deitrick - 15 Apr 2008 16:51 GMT
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

> Hello all
>
[quoted text clipped - 8 lines]
>
> Any help would be really great!  thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.