Modifying Text Files

C

Craig

I'm using Access 2003.

I'm opening, modifying, and saving many text files in many different
directories and subdirectories. Although the names are different, each text
file is the same in layout. My code opens each file, then searches each line
until it gets to a dotted line ("--------"). All I want is the data that
follows this dotted line. The file is then saved over itself. Then, it
moves on to the next file.

However, I keep getting a "runtime error #91 Object Variable or With Block
Not Set" error message at the "createtextfile" line of code below. Any
thoughts?


Sub ModifyTextFiles()
Dim fs As FileSearch
Dim FullFilePath As String
Dim MyField
Dim fso, i As Integer, s As String
Dim txtout
Set fso = CreateObject("Scripting.FileSystemObject")

z = InputBox("Enter Pathname:" & vbCrLf & vbCrLf & "i.e., C:\Windows\", ,
"C:\Documents and Settings\Desktop\MyDirectory\")

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = z
.SearchSubFolders = True
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.count & _
" file(s) found."
For i = 1 To .FoundFiles.count
FullFilePath = Trim(.FoundFiles(i))
s = ""

Open FullFilePath For Input As #1

Do While Not EOF(1)
Line Input #1, MyField

If Left(fieldA, 10) = "----------" Then
Do While Not EOF(1)
Line Input #1, MyField
s = s & Trim(MyField) & vbCr
Loop
Else
GoTo skip
End If

Set txtout = fso.CreateTextFile(FullFilePath, True)
txtout.WriteLine s
txtout.Close

Set txtout = Nothing
Set fso = Nothing
skip:
Loop
below:
Close #1
Next i
End If
End With
MsgBox "All Done."
End Sub


Thanks for any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top