VBA-Import-Export
VBA-Import-Export copied to clipboard
Export & Import VBA code for use with Git (or any VCS)
VBA Import & Export Add-in for MS Excel
The VBA Import & Export Add-in is an Add-in for Microsoft Excel that allows
you to import and export VBA code to and from Excel Workbooks (.xlsm files)
easily. This allows VBA code to be stored in plain text files alongside the
.xlsm file. This is essential for effectively utilizing Git in a VBA project
(or any other VCS).
Installation
- Download the Add-in: VBA-Import-Export.xlam (version 0.4.0)
- Add and enable the Add-in in Excel
- In Excel, Check the
Trust access to the VBA project modelcheck box located inTrust Centre -> Trust Centre Settings -> Macro Settings -> Trust access to the VBA project model.
Usage
The add-in can be used from Developer tab of the Excel ribbon menu and in the menu of the VBA IDE. Both menus provide the same commands.
Getting started
- Save your
.xlsmfile into a folder. - Use the
Make Config Filecommand to make aCodeExport.config.jsonfile in the same folder as the.xlsmfile. This records a list of VBA files and references. - Use the
Exportcommand to export the VBA code. Notice the VBA code present in the same folder as your.xlsmfile. - Save and close your Excel workbook.
- (Optional) Commit the contents of your project directory into Git or any other VCS system.
Important: VBA-project-template provides config files to ensure Git and text editors play nicely with your project files.
When you return to work on the VBA project:
- (Optional) Checkout a version of your project from Git or the VCS system you are using.
- Open the Excel workbook (
.xlsmfile) in Excel. - Use the
Importcommand to import the VBA code from the project directory* and the references listed in the configuration file. - Regularly use the
Savecommand to save your changes to the file system while you work. - Use the
Make Config Filecommand to update the config file when modules or references are added or removed. - When you're finished, use the
Exportcommand to export your work, then save and close the Excel workbook.
* Only files listed in the configuration file will be imported.
Safety tips
Here's some tips to avoid loosing data while using this Add-in:
- Do regular backups! Use the method that you won't forget. My favourite method is to use Git. Any versioning system would also work.
- If you make changes in the Excel document, don't edit the files in the file system before you
Export. The inevitableExportwill overwrite your changes. - If you make changes in the Excel document, don't
Importbefore usingSaveorExport. You will just overwrite your changes with what you started with. Saveregularly to avoid making the mistake above.
The configuration file
The CodeExport.config.json file declares what gets imported and exported from
an Excel workbook. The config file must be in the same directory as the .xlsm
file. The config file can be edited in a text editor to make advanced
adjustments that the Make Config File command cannot do. A comprehensive
example config file can be found at
test-projects/comprehensive/CodeExport.config.json.
The config file uses the JSON file format
and the configuration properties are:
VBAProject Name- The name of the VBAProject. Will be set on import. Must not contain any spaces.Module Paths- A file system path for every VBA module that will be imported and exported by CodeExport. These may be relative or absolute paths.Base Path- A prefix to be prepended to all relative paths inModule Paths.References- A list of reference definitions. Each reference described will be referenced on import and dereferenced on export.
Importing, Saving & Exporting
The Import command will:
- Import all the modules specified in the
Module Pathsconfiguration property. Existing modules in the Excel file will be overwritten. - Add all library references declared in the
Referencesconfiguration property. Existing library references in the Excel file will be overwritten. - Set the VBAProject name as declared in the
VBAProject Nameconfiguration property.
The Save command will:
- Export all the modules specified in the
Module Pathsconfiguration property. Existing files in the file system will be overwritten.
The Export command will:
- Do the same as the
Savecommand. - Dereference libraries declared in the
Referencesconfiguration property.
Support
You can submit questions, requests and bug reports to the issues list. Github pull requests are also welcome.
Authors and Attribution
- Scott Spence - Author (spences10/VBA-IDE-Code-Export)
- Matthew Palermo - Author (mattpalermo/VBA-Import-Export)
- Tim Hall - Author of the library VBA-JSON
- Kevin Conner - Author of the Save action
See Also
- vba-blocks - A VBA package manager in development by Tim Hall. It will hopefully supersede this add-in.
- VBA-IDE-Code-Export - Scott Spence's version of this add-in.