I have the code below copied verbatim from Excel help. I am trying to open a .txt file, add text to the end of the file and save the .txt file. I have created a test file that is c:\testfile.txt and cannot figure this simple procedure out. When I run I get Run-time error 5 - Invalid procedure call or argument. It is hanging up on the line that I underlined.
Sub OpenTextFileTest()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\testfile.txt", ForAppending, TristateUseDefault)
f.write "Hello world!"
f.Close
End Sub
Bookmarks