Hi All - I am using this code to basically re-write a range in Column A to a text file. My requirements have now changed to where I need to append to the text file with the current cell in Column A rather than re-writing the entire range. For example, I have the users scanning barcoded part numbers in column A starting at Row 9. Once scanned, the active cell moves down. What I need to do is append to the file at each cell, but cannot seem to get it without getting 'bad file' errors when changing 'CreateTextFile' to 'OpenTextFile'
Code:
Public Sub SaveTextToFile()
Dim iCntr
Dim filePath As String
filePath = "C:\scripts\SMTscans.txt"
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim fileStream As TextStream
Set fileStream = fso.CreateTextFile(filePath)
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For iCntr = 9 To LastRow
fileStream.WriteLine Range("A" & iCntr)
Next iCntr
fileStream.Close
End Sub