Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JEB JEB is offline
external usenet poster
 
Posts: 40
Default HELP! Writing Text file from Excel Spreadsheet.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HELP! Writing Text file from Excel Spreadsheet.

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   Report Post  
Posted to microsoft.public.excel.programming
JEB JEB is offline
external usenet poster
 
Posts: 40
Default HELP! Writing Text file from Excel Spreadsheet.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HELP! Writing Text file from Excel Spreadsheet.

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   Report Post  
Posted to microsoft.public.excel.programming
JEB JEB is offline
external usenet poster
 
Posts: 40
Default HELP! Writing Text file from Excel Spreadsheet.

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default HELP! Writing Text file from Excel Spreadsheet.

not smart enough. Have been trying to get your code to write more than 1
column. Also have been having trouble accessing this web site. Need to write
A!:F50 to text file so can speed up mail merge. Have been told this will
eliminate word searching full sheet. Had on responce to this and all I get
when trying to acess is blank page. I got here by going into word then
getting here. any Help greatly appreciated.
Thanks



"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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a macro in Excel that Refreshes External Imported Text File [email protected] Excel Programming 0 August 17th 07 08:29 PM
writing to text file ADK Excel Programming 7 July 13th 07 06:13 PM
Writing to a text file scantor145[_9_] Excel Programming 6 June 30th 05 08:23 PM
Writing to a text file Rachel Curran Excel Programming 0 October 8th 04 09:44 AM
Writing a text file from Excel using VBA ... a small issue ajames54 Excel Programming 3 December 3rd 03 03:35 PM


All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"