Dim fso As Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim c As Range
Dim filename As Variant
Dim colcount As Integer
colcount = 2
Worksheets("ShipmentTracker(AL3)").Activate
filename = InputBox("Enter File Name", "file name", Worksheets("ShipmentTracker(AL3)").Cells(3, 2).Value)
Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile("C:\Users\soora\Desktop\Meng Project\Shipment Tracker" & filename, ForAppending, True)
For Each c In Range("A9", Range("A9").End(xlDown))
For i = 1 To colcount
ts.Write c.Offset(0, i - 1).Value
If i < colcount Then ts.Write vbTab
Next i
ts.WriteLine
Next c
ts.Close
Set fso = Nothing
I am taking filename
as input and using that to create a new file into which I want to write data. But this does not work.
I want to create files with user input filename
and write data to it.