I have this VBA code to create a text file, convert my data to tab delimited, and then write the data to the file. This code is added at the end of an 80 line macro that formats the document to be identical to another in formatting to be compared as .txt files through Notepad++.
Everything is working properly except actually writing the data to the file. I see that the file has been interacted with because of the last saved date and time, but it is not writing any of the data.
Dim rCell As Range, ws As Worksheet, rRow As Range
Dim sOutput As String, sFname As String, lFnum As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
'Open a text file to write
sFname = "\\SERVER1\Info.txt"
lFnum = FreeFile
Open sFname For Output As lFnum
'Loop through the rows
For Each rRow In ws.UsedRange.Rows
'Loop through the cells in the rows
For Each rCell In rRow.Cells
If Not IsEmpty(rCell) Then
sOutput = sOutput & rCell.Value & vbTab
End If
Next rCell
'remove the last tab
If sOutput <> "" Then
sOutput = Left(sOutput, Len(sOutput) - 1)
End If
'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
'Close the file
Close lFnum
MsgBox "Done!"
Bookmarks