Visual Basic for Applications/Use Log Files from VBA

Summary
At times it is useful to write strings to a text file from VBA. For example, for listing files, their hashes, or for simply logging errors. Text files are here intended to mean files with the .txt suffix. There are several procedures listed in the code module for both writing and reading such files.

Writing to Text Files and Logs

 * The procedure SendToLogFile APPENDS a string to a text file.  The user optionally selects his own path and file name, but there is no OVERWRITE choice with this method.   If user parameters are not given then the defaults are used. This procedure places the parameter string in line with a time date string, with each record entry on a new line.
 * The procedure LogError1 is intended to APPEND log errors, and is an example of the Print# statement.  It is assumed here that the log file will always be placed in the same folder as the calling Workbook.   As such, no path check is needed, and the minimum of coding applies.   All formatting of the parameter text is assumed to be done externally.   Readers can find format details for Print# in VBA help, and might also care to compare the advantages of using the Write# statement instead.
 * The procedure LogError2 is also intended to APPEND log errors and performs the same task as LogError1.  It is however an example of the OpenTextFile method of the Scripting object.   This procedure needs a reference in the VBA editor to Microsoft Scripting Runtime.    Notice that this log will write every successive record into the first line unless vbNewLine characters are included at the end of the parameter string itself.
 * Procedure WriteToFile REPLACES any existing text, as opposed to appending it to any existing entries.
 * There are conventions in logging. Logging with a text file (.txt) means placing each record on the same line with the individual fields separated by a single tab character.  The  number of fields is the same for each record.   Another convention is to use a comma-separated file format (.csv) where the fields are separated by commas instead of tabs.    Both of these formats can be imported into MS Office applications,though users should pay particular attention as to how different log writing methods handle quotes.

Reading Text Files and Logs

 * VBA can also read text files into code for processing.  However, once the notion of reading files is introduced, the choice of writing formats becomes more important.   In addition, file reading can place more demands on error handling, and testing for path integrity.
 * The procedure GetAllFileText returns the entire contents of a .txt file .  Readers should first confirm that the text file exists.   File utilities elsewhere in this series would suit this purpose.
 * The procedure GetLineText returns an array of text file lines.  The same comments regarding early file checks also apply in this case.