VBA Snippets: Open a File for Appending

MicrosoftThis post is part of the series on VBA Snippets.

The below VBA script can be used to open a text file for appending and then write a line to the bottom of the file; it could be combined with the example in this eries’ last post on selecting records from a Microsoft Dynamics ODBC connection to out put multiple lines.

The highlighted section is the path of the output file.

Dim objFSO As FileSystemObject
Dim objTextStream As TextStream

Const fsoForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextStream = objFSO.OpenTextFile(output path, fsoForAppending, True)

'Write line
objTextStream.WriteLine data to output

objTextStream.Close
Set objTextStream = Nothing

What should we write about next?

If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.

Your Name

Your Email

Suggested Topic

Suggestion Details

Leave a Reply

Your email address will not be published. Required fields are marked *