S
Steph
Hello. I was hoping someone could make a monir edit to a small piece of
code I have. Thanks to Dick Kusleika, I have the following code that writes
the data on Sheet1 onto a text file. This works great, with one small
exception - There is an extra blank line at the bottom of the text file.
The text file is being used as an EDI transfer, and apparently the EDI is
very picky about extra blank lines! How can I edit the code so the extra
vbnewline is not added at the bottom?? Thanks so much!!
Sub SaveAsTextFile()
Dim sh As Worksheet
Dim rRow As Range
Dim rCell As Range
Dim sOutput As String
Dim lFnum As Long
Dim sFname As String
Set sh = Worksheets("Sheet1")
For Each rRow In sh.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & vbTab
Next rCell
sOutput = sOutput & vbNewLine
Next rRow
lFnum = FreeFile
sFname = "C:\Testfile.txt"
Open sFname For Output As lFnum
Print #lFnum, sOutput
Close lFnum
End Sub
code I have. Thanks to Dick Kusleika, I have the following code that writes
the data on Sheet1 onto a text file. This works great, with one small
exception - There is an extra blank line at the bottom of the text file.
The text file is being used as an EDI transfer, and apparently the EDI is
very picky about extra blank lines! How can I edit the code so the extra
vbnewline is not added at the bottom?? Thanks so much!!
Sub SaveAsTextFile()
Dim sh As Worksheet
Dim rRow As Range
Dim rCell As Range
Dim sOutput As String
Dim lFnum As Long
Dim sFname As String
Set sh = Worksheets("Sheet1")
For Each rRow In sh.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & vbTab
Next rCell
sOutput = sOutput & vbNewLine
Next rRow
lFnum = FreeFile
sFname = "C:\Testfile.txt"
Open sFname For Output As lFnum
Print #lFnum, sOutput
Close lFnum
End Sub