biocentrism
Board Regular
- Joined
- Jul 28, 2014
- Messages
- 187
I have the following code which is supposed to create a text file. Despite the Filename existing, the program does not delete the file before creating it. It Appends to the existing text file so that the text keeps getting added each time I export. Any ideas how to get this working? I am new to VBA and just trying to debug code someone else has written. Thank you!
Code:
Sub CreateTextFile ()
Dim Output As String
Dim Filename As String
Filename = ThisWorkbook.Path & "\AccountList.txt"
'Deletes File if it Exists <---not working, it seems it is either not triggering an error or is not deleting
On Error Resume Next
Kill Filename
On Error Goto 0
'Write Output to File
Open Filename & ".txt" For Append As #1
Print #1, Output
Close #1
End Sub