VBA code to export the data from Excel to Text file

preview_player
Показать описание
Codes:-
Option Explicit

Sub txt_Msg()

Dim s As String, savefile As String

s = InputBox("please enter a string.")

savefile = Application.GetSaveAsFilename(filefilter:="Text Files (*.txt),*.txt")

Open savefile For Output As #1
Write #1, s
Close #1

End Sub

Sub txt_selection()

Dim savefile As String, nr As Integer, i As Integer

nr = Selection.Rows.Count

savefile = Application.GetSaveAsFilename(filefilter:="Text Files (*.txt),*.txt")
Open savefile For Output As #1

For i = 1 To nr

Write #1, Selection.Cells(i, 1)

Next i
Close #1
End Sub
Рекомендации по теме
Комментарии
Автор

this helped me a lot in my project to export as json thank you so much, i wished you had shown as print rather than write which prints "" as it was messing up the json until i read the comment below and it worked out. Thanks again

saumitrapalchoudhori
Автор

How we can add comma after every value, if we are printing cell values of a particular column?

AnjaliSingh-btyv
Автор

Works great but can you help to remove the " " from every line in the text file .Please?

jonnathanjon
Автор

Thank you for sharing. I have tried your text selection code on A1:B5 range but it can only able to export A1:A5. means first column only

syedaliraza
join shbcf.ru