In VBA you may occasionally want to store some settings outside of the document. The registry is one way, but I often try to keep it in INI files as automated documents get spread through email easily, but usually do not get ‘uninstalled’ hence the settings will never be cleaned up. I’d rather leave an orphaned file than polute the registry. Other advantages are that its easier to support because a user can email them, or its easier to edit by a user.
The download below contains two VBA modules. One, which originates from the excellent Excel site by Erlandsen Data Consulting, uses the Windows API to directly write to INI files. The other one, which I created myself, doesn’t handle files directly, but uses a string to store it in. If you’re looking specifically at files (not strings) to store the INI stuff in, then you may also want to check out Karl Petersons kpINI, another excellent piece of code that even allows for enumerating sections and contents of INI files.
My code was originally created to store settings in an INI style in an Outlook note, hence the storage in a string. It has some value over all the other INI code you’ll find flying around as you can store the string anywhere you like. In custom properties or into the core of a document for example, you might even email it and have it parsed at the receiving end. In my case the note with the settings would be synchronized to a PDA, on which an application could then access the same settings.
The code can be downloaded here (downloaded 1097 times).
[ad name=”468×60 Banner”]