Hello,
I am new here and still learning VBA. I am struggling with my code.
I have multiple sheets that I need to save as a txt file in the same workbook. However, the code is only working when the sheet is selected. Can someone help me out with my code?
Sub DOTtxt()
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
Dim j As Long
Dim ws As Worksheet
Set ws = wb.Sheets("DOT")
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim my_textfile As Scripting.TextStream
Set my_textfile = fso.CreateTextFile("file path to my folder.txt")
Dim rownum As Long, var As Variant
rownum = 2
For j = 2 To Range("a1000000").End(xlUp).Row
var = Cells(rownum, 1).Value
'going to write in the text file create above
my_textfile.WriteLine var
rownum = rownum + 1
Next
my_textfile.Close
End Sub
I am new here and still learning VBA. I am struggling with my code.
I have multiple sheets that I need to save as a txt file in the same workbook. However, the code is only working when the sheet is selected. Can someone help me out with my code?
Sub DOTtxt()
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
Dim j As Long
Dim ws As Worksheet
Set ws = wb.Sheets("DOT")
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim my_textfile As Scripting.TextStream
Set my_textfile = fso.CreateTextFile("file path to my folder.txt")
Dim rownum As Long, var As Variant
rownum = 2
For j = 2 To Range("a1000000").End(xlUp).Row
var = Cells(rownum, 1).Value
'going to write in the text file create above
my_textfile.WriteLine var
rownum = rownum + 1
Next
my_textfile.Close
End Sub