Wednesday, 7 August 2013

Convert excel to text using VB-macro (including line breaks within cells)

Convert excel to text using VB-macro (including line breaks within cells)

I would like to convert an excel sheet into several text files. The excel
sheet contains two columns, column A gives the name of generated text
files, column B provides content. Column B contains line breaks within
cells. The conversion works, but line breaks are not imported to the text
file-all text is in one line. How can I do that? I am using following
code:
Private Sub CommandButton1_Click()
Dim oTxt As Object
For Each cell In Ark1.Range("A1:A" & Ark1.UsedRange.Rows.Count)
' you can change the sheet1 to your own choice
saveText = cell.Text
Open "H:\Webshop_Zpider\S-solutions" & saveText & ".txt" For Output As #1
Print #1, cell.Offset(0, 1).Text
Close #1
Next cell
End Sub
Can anybody help me with that? Thanks, Kerstin

No comments:

Post a Comment