VBA code for creating text files based on data fields

I needed to create a lot of text files that were similar to one another except they were altered depending on a simple database. It would be something like an old-school MS Word “mail merge,” except it would create separate text files. I wanted an easy-to-use tool, so I put together something in Excel using VBA. The tool could create thousands of text files that vary on (up to) 15 different fields (i.e., dimensions). For example, this tool could create many HTML files that are all alike except for a product description, a photo, and a URL link. My original purpose for creating the tool was to setup the coarse-grained parallelization of a CPU-intensive Monte Carlo simulation.

In essence, the parent text should be put into one spreadsheet (“Body of TXT files”), and the codes that will be ‘replaced into’ the parent text for each file should be put in the other spreadsheet (“Definitions of Replacements”). The Excel file shows a simple example.

In “Body of TXT files,” any blank cells to the left of the text will yield tabs in the created text files. This is handy for dealing with tab-indented code. When text with leading tabs is copied from a text editor into “Body of TXT files,” Excel replaces the tabs with blank cells. This tool turns them back into tabs.

 
– Eric DeRosia