Print cell value even with Alt+Enter's

spacely

Board Regular
Joined
Oct 26, 2007
Messages
248
Hello,

I'm using a simple VBA macro to save a block of cell's values to a file. This works well if there's one value per cell. But a couple cells have wrapped text that I want also printed exactly as seen in the cell. It uses Alt+Enter to wrap. I guess that doesn't translate into DOS text editors, since Wordpad shows long lines, and the program reading the block is crashing. Not sure how to attach a sample file, so I'll paste best i can here.

Here's the code:

Sub SaveDEL()
' shift+ctrl+s
' select the cell with the range limits and file path/name, and then run this.
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer, WrdArray() As String, UpperLeft() As String, LowerRight() As String, UpperLeftRow As Integer, UpperLeftColumn As Integer, LowerRightRow As Integer, LowerRightColumn As Integer

WrdArray() = Split(ActiveCell.Value)
myFile = WrdArray(2)
UpperLeft() = Split(WrdArray(0), ",")
UpperLeftRow = UpperLeft(0)
UpperLeftColumn = UpperLeft(1)
LowerRight() = Split(WrdArray(1), ",")
LowerRightRow = LowerRight(0)
LowerRightColumn = LowerRight(1)
ActiveSheet.Range(Cells(UpperLeftRow, UpperLeftColumn), Cells(LowerRightRow, LowerRightColumn)).Select

Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, Spc(1); cellValue
Else
Print #1, Spc(1); cellValue,
End If
Next j
Next i
Close #1

End Sub

When the print statement comes upon a cell with wrapped text, it prints all as one line. Even if I separate lines with CHAR(10), like:

="END" & CHAR(10) &
"ReallyEnd"

Hope there's a solution to this. Thanks for any help you can offer :)

Dave
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
As a side note, if I open the resulting text file with the non-wrapping line into Textpad, change the SaveAs Type to "PC", then the resulting line does wrap. Someone tells me the new line character is somehow for LINUX? So, appears something is at the correct end of lines, just not what Windows wants, I guess.
 
Upvote 0
Well, I found what works:

Print #1, Spc(1); Replace(cellValue, vbLf, vbCrLf)

But I wonder now if it's excel putting in LINUX LF line breaks, or somehow they exist because of where I copied the text data.
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top