HOW TO EXPORT TEXT FILE IN EXCEL USING VBA CODE

1st Insert module then copy past below code.

Sub test()
Dim myFile As String
lr = Cells.Find("*", SearchDirection:=xlPrevious).Row
Path = ActiveWorkbook.Path
myFile = Path & "\aaa.txt"
TextFile = FreeFile
Open myFile For Output As TextFile
For i = 1 To lr
Print #TextFile, Range("A" & i).Value,
Print #TextFile, Range("B" & i).Value
Next
Close #TextFile
End Sub

Comments

Popular Posts