Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Pardon my sence of urgency here, but I'm stuck and need help.
I have a worksheet that contains only one column of string data that I need to write to an MS-DOS formated Text file on my PC (for later use). What is the simplest way to do it. (The data resides in colmun "A" and contains anywhere from 50 to 160 rows). Thanking you in advance. JEB |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can use this macro to write out Column A's content...
Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub Rick "JEB" wrote in message ... Pardon my sence of urgency here, but I'm stuck and need help. I have a worksheet that contains only one column of string data that I need to write to an MS-DOS formated Text file on my PC (for later use). What is the simplest way to do it. (The data resides in colmun "A" and contains anywhere from 50 to 160 rows). Thanking you in advance. JEB |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rick;
Thank you very much. It worked. Is there, however, anyway to eliminte the LFCR as the first character of the record? My data string is 1500 bytes and I need to output that to the text file starting in position 1. It seems that I have a 1 byte displacement. Also, do you know of anyway that in creating a string, to maintain a given length of a field which is being concatenated to the string? For example, if I have a 25 byte 'name' field that only contains 18 characters, I want to move the whole 25 bytes rather than the first 18. Thank you again for your help. JEB "Rick Rothstein (MVP - VB)" wrote: You can use this macro to write out Column A's content... Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub Rick "JEB" wrote in message ... Pardon my sence of urgency here, but I'm stuck and need help. I have a worksheet that contains only one column of string data that I need to write to an MS-DOS formated Text file on my PC (for later use). What is the simplest way to do it. (The data resides in colmun "A" and contains anywhere from 50 to 160 rows). Thanking you in advance. JEB |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can use this code to produce a file that won't start with a CrLf
combination... Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next Do While Left$(ColumnText, 2) = vbCrLf ColumnText = Mid$(ColumnText, 3) Loop FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub As for your other question, it was not clear to me if you meant that for use in the above code or for some other code you have. If you meant for use in the above, change the statement in the For-Next block to this... ColumnText = ColumnText & Format$(Range("A" & CStr(X)).Value, _ "!" & String(25, "@")) & vbCrLf If you meant for use in other code, then assuming your text is in a variable named MyText, you would use this.... Format$(MyText, "!" & String(25, "@")) which is identical to this.... Format$(MyText, "!@@@@@@@@@@@@@@@@@@@@@@@@@") that is, a pattern string composed of an exclamation mark followed by as many @ symbols as you want characters in your output field (each character in MyText fills in one of the @ symbols, any unfilled @ symbols become spaces... the exclamation mark says to start filling in the@ symbols from the left side). Rick "JEB" wrote in message ... Rick; Thank you very much. It worked. Is there, however, anyway to eliminte the LFCR as the first character of the record? My data string is 1500 bytes and I need to output that to the text file starting in position 1. It seems that I have a 1 byte displacement. Also, do you know of anyway that in creating a string, to maintain a given length of a field which is being concatenated to the string? For example, if I have a 25 byte 'name' field that only contains 18 characters, I want to move the whole 25 bytes rather than the first 18. Thank you again for your help. JEB "Rick Rothstein (MVP - VB)" wrote: You can use this macro to write out Column A's content... Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub Rick "JEB" wrote in message ... Pardon my sence of urgency here, but I'm stuck and need help. I have a worksheet that contains only one column of string data that I need to write to an MS-DOS formated Text file on my PC (for later use). What is the simplest way to do it. (The data resides in colmun "A" and contains anywhere from 50 to 160 rows). Thanking you in advance. JEB |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Again, my sincere thanks.
"Rick Rothstein (MVP - VB)" wrote: You can use this code to produce a file that won't start with a CrLf combination... Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next Do While Left$(ColumnText, 2) = vbCrLf ColumnText = Mid$(ColumnText, 3) Loop FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub As for your other question, it was not clear to me if you meant that for use in the above code or for some other code you have. If you meant for use in the above, change the statement in the For-Next block to this... ColumnText = ColumnText & Format$(Range("A" & CStr(X)).Value, _ "!" & String(25, "@")) & vbCrLf If you meant for use in other code, then assuming your text is in a variable named MyText, you would use this.... Format$(MyText, "!" & String(25, "@")) which is identical to this.... Format$(MyText, "!@@@@@@@@@@@@@@@@@@@@@@@@@") that is, a pattern string composed of an exclamation mark followed by as many @ symbols as you want characters in your output field (each character in MyText fills in one of the @ symbols, any unfilled @ symbols become spaces... the exclamation mark says to start filling in the@ symbols from the left side). Rick "JEB" wrote in message ... Rick; Thank you very much. It worked. Is there, however, anyway to eliminte the LFCR as the first character of the record? My data string is 1500 bytes and I need to output that to the text file starting in position 1. It seems that I have a 1 byte displacement. Also, do you know of anyway that in creating a string, to maintain a given length of a field which is being concatenated to the string? For example, if I have a 25 byte 'name' field that only contains 18 characters, I want to move the whole 25 bytes rather than the first 18. Thank you again for your help. JEB "Rick Rothstein (MVP - VB)" wrote: You can use this macro to write out Column A's content... Sub SaveColumnA() Dim X As Long Dim FF As Long Dim ColumnText As String For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf Next FF = FreeFile Open "c:\temp\test.txt" For Output As #FF Print #FF, ColumnText Close #FF End Sub Rick "JEB" wrote in message ... Pardon my sence of urgency here, but I'm stuck and need help. I have a worksheet that contains only one column of string data that I need to write to an MS-DOS formated Text file on my PC (for later use). What is the simplest way to do it. (The data resides in colmun "A" and contains anywhere from 50 to 160 rows). Thanking you in advance. JEB |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing a macro in Excel that Refreshes External Imported Text File | Excel Programming | |||
writing to text file | Excel Programming | |||
Writing to a text file | Excel Programming | |||
Writing to a text file | Excel Programming | |||
Writing a text file from Excel using VBA ... a small issue | Excel Programming |