Visual Basic for Applications/Backup Text Boxes on Close

Summary
'''This VBA code is written for Microsoft Excel but is easily adapted to other applications in the MS Office set. It saves all of the text from a user form's text boxes in a log file whenever the form is closed. Then later, on re-opening the form, or at any other time, the user can fill the boxes with the most recent saved text.'''

The VBA Code

 * The code needs a user form called Userform1, two text boxes, TextBox1 and TextBox2, and a command button called CommandButton1.  Set the UserForm1 property ShowModal to false for convenient study.   Copy the code below into the three respective modules and save the workbook with an xlsm file suffix.
 * Any code that is found in text boxes will be saved when the user form closes.  This includes inadvertent closure of the user form or the deliberate closing of the workbook.   It does not of course protect against the effect of power failures.   The saving of data happens without intervention, so may need consideration if the storage of sensitive data is to be avoided.
 * The log file is called SavedText.txt, and will be found in the same folder as the workbook.  If a log file of that name is not found, then it will be made by the code for use. The log file has only two fields, the text box name and the string contents found in it.   The comma separator was avoided in favor of the less likely encountered string >Break<.
 * The saving function runs from the UserForm_QueryClose event. SaveTextBoxes makes a log string in a userform controls loop, then exports the string via WriteToFile.
 * WriteToFile makes a log file if it does not exist, but otherwise overwrites any text that it finds, so that only the most recently saved session will be found there. Users who employ the logging procedure elsewhere should note that an extra Cr and Lf are stored at the end of logged entries, and might need consideration.
 * RestoreTextBoxes runs only by pressing CommandButton1, so the user chooses whether or not to insert text.  GetAllFileText imports all of the log file's contents at once with the file retaining contents until it is next overwritten.   The string is split twice, once to break it into lines, that is, one for each text box record, and then again to break each record into its two fields for matching control names in the main transfer loop.

Code Changes
8 March 2019: Changed data separator from comma to other, in Standard Module