Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 sOutput = Left(sOutput, Len(sOutput) - 1) lFnum = FreeFile sFname = "C:\Testfile.txt" Open sFname For Output As lFnum Print #lFnum, sOutput Close lFnum End Sub -- HTH ------- Bob Phillips "Steph" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
Loop help | Excel Discussion (Misc queries) | |||
For/Loop skipping one value in loop only | Excel Programming | |||
Worksheet_Change - loop within a loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |