0

I have the following macro that is should write new data onto a new line in a text/csv file, however it overwriting the existing text in the file, I thought that write wrote to a new line as opposed to print. I am not sure what I am doing wrong

Sub picking()

Range("d14").NumberFormat = "mm/dd/yyyy"
Range("d14").Value = Now

Range("e14").NumberFormat = "hh:mm"
Range("e14").Value = Now

Range("e17").Value = "Picking"

Call outputcsv

End Sub



Sub outputcsv()

Dim Fullpath As String
Dim outputstring As String

Fullpath = Worksheets("Maintence").Range("c5")

Open Fullpath For Output As #1
outputstring = Worksheets("CSV").Range("A1")
Write #1, outputstring
Close #1
End Sub
  • The FileSytemObject library is a nicer way to write files. You may want to use that instead: https://stackoverflow.com/questions/11503174/how-to-create-and-write-to-a-txt-file-using-vba https://stackoverflow.com/questions/9442215/reading-and-writing-a-csv-file-using-filesystemobject – Tragamor Sep 30 '21 at 19:31

1 Answers1

1

You just need to change...

Open Fullpath For Output As #1

...to...

Open Fullpath For Append As #1

Note that "Output" changes to "Append."

Also note that "Append" will create the file - just as Output does - if it doesn't already exist. No need to pre-create it.

John Joseph
  • 1,003
  • 1
  • 10
  • 20