VBA code to export the data from Excel to Text file

Опубликовано: 06 Октябрь 2024
на канале: The Business Analyst
11,025
70

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