Search notes:

VBA statement: open

open can be used to open a file for reading or writing.
Use freeFile to determine the next »file descriptor« for open.

open for output

sub writeToFile()

  open environ("TEMP") & "\vba-file-test.txt" for output as #1

  print #1, "Hello world"
  print #1, "Second line"

  close #1

end sub
Github repository about-VBA, path: /language/statements/open/open-for-output.bas

See also

The print# statement.
The open statement and character encodings
GetTempFileName to create a name for temporary files.
The functions in the File module, especially slurpFile (which reads an entire file into a string) and its corresponding flushToFile.
VBA statements

Index