I was studying this code from Chandoo. My current project is to take some Excel ranges and put them in a text file. The post below is perfect.
I would like to expand this by moving the text file to a folder that is created by the macro.
I successfully created a folder and using the code below created a text file.
Issue:
I cannot create the code to get the text file to move to the folder.
Thanks for your help
https://chandoo.org/wp/save-range-as-text-using-vba/
>>> use code - tags <<<
I would like to expand this by moving the text file to a folder that is created by the macro.
I successfully created a folder and using the code below created a text file.
Issue:
I cannot create the code to get the text file to move to the folder.
Thanks for your help
https://chandoo.org/wp/save-range-as-text-using-vba/
>>> use code - tags <<<
Code:
Sub saveText2()
Dim filename As String, lineText As String
Dim myrng As Range, i, j
filename = ThisWorkbook.Path & "\textfile-" & Format(Now, "ddmmyy-hhmmss") & ".txt"
Open filename For Output As #1
Set myrng = Range("data")
For i = 1 To myrng.Rows.Count
For j = 1 To myrng.Columns.Count lineText = IIf(j = 1, "", lineText & ",") & myrng.Cells(i, j)
Next j
Print #1, lineText
Next I
Close #1
End Sub
Attachments
Last edited by a moderator: