I didn't want to leave this post unsolved, just in case anyone comes across it in desperate need. I used Microsoft Scripting system to do the deed. Use the link above to find out more. This has to be selected from the Tools-Reference list in VBA (not Excel). If you don't do this, the code will show error after error. Below is a simplified version of the code to write data from 15 columns to an arbitrary number of rows. If you have fixed numbers of rows and columns, this makes the task much easier:
Private Const ForReading = 1
Private Const ForWriting = 2
Private Const ForAppending = 8
Private Const fnamePath = "C:\path\name.txt" 'change this accordingly
Private Const NUMBER_OF_COLUMNS = 15 'up to you
Private Const ERROR_COUNT_ROWS = 20 'up to you
Sub writeFile()
Dim fso, MyFile, FileName, TextLine
Dim x, r As Long 'x counts columns, r counts rows
Dim endloop As Integer: endloop = False
Dim v As Variant: v = 0
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = fnamePath
If (fso.FileExists(FileName)) Then
'check that the user wants to overwrite
End If
Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
Do While endloop = False And r < ERROR_COUNT_ROWS 'or have a fixed length
For x = 1 To NUMBER_OF_COLUMNS
v = Sheets("SheetName").Range("A1").Offset(r, x - 1)
MyFile.WriteLine v
Next x
r = r + 1
If v <> 0 Then endloop = True 'have some kind of end check here if not fixed length file
Loop
MyFile.Close
MsgBox "File Saved."
End Sub
Sub readFile()
Dim fso, MyFile, FileName, TextLine
Dim x, r As Long
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = fnamePath
If Not (fso.FileExists(FileName)) Then
MsgBox "File not found."
Exit Sub
End If
Set MyFile = fso.OpenTextFile(FileName, ForReading)
r = 0
Do While MyFile.AtEndOfStream <> True
For x = 1 To NUMBER_OF_COLUMNS
Sheets("SheetName").Range("A1").Offset(r, x - 1) = MyFile.ReadLine
Next x
r = r + 1
Loop
MyFile.Close
MsgBox "File Read."
End Sub
I hope this helps someone, someplace, sometime...
Bookmarks