Paul Terwilliger
Paul Terwilliger

Reputation: 1646

Microsoft Access import vba file

I have a Microsoft Access file, and in it there is a lot of VBA code. I would like to collaborate with this code on GitHub.

Unfortunately, the VBA code is embedded within the MS Access database and not as separate files. This means that changes are not tracked or observable from GitHub.

I would like to have all of the VBA code (approximately 10 files) as separate files. I would like to import these files into the MS Access database. This method would allow me to view and track the changes to the files using GitHub.

If this were a Python project, I would write a separate module and import it with:

import my_module

Is there a way to import VBA files into a MS Access database?

Upvotes: 1

Views: 1552

Answers (1)

Mathieu Guindon
Mathieu Guindon

Reputation: 71157

Absolutely. Right-click the VBA project in the VBE's Project Explorer (Ctrl+R), select Import... and then select all the files you want to import1. Or just drag-and-drop them from the file system into the Project Explorer.

You can export a file by right-clicking a module in the Project Explorer, and selecting Export to supply a path2.

By exporting the files to your local git repository, all you need to do is keep the VBA project synchronized with the files on the file system.

Rubberduck (an open-source VBIDE add-in project I manage) can do this for you within the VBE, with its Source Control panel which is designed to work like Visual Studio's Team Explorer, i.e. it synchronizes the files into the VBE, lets you commit, pull, push, branch, merge, etc. There's no diff tool for now, but you probably have a favorite one already, and all git commands the Source Control panel automates for you can be done using your favorite command-line tool - it's just a UI... and we're working on a number of bugs with it, so the feature is currently deemed "experimental" and may throw exceptions, notably on push (something about credentials isn't right).

Otherwise, you can probably whip up a little VBA macro that iterates all modules in the VBA project, and exports them; then another that iterates all files in a given folder, and imports them (overwrites in-IDE modules). There are plenty of examples on this site; none of this is rocket science, but if you go with a VBA solution you'll need to enable programmatic access to the VBIDE object model, which may or may not be a security concern for you (Rubberduck, or any other VBIDE add-in, wouldn't need that permission to manipulate the modules).


1 not sure the VBE allows multiple selections on import. Rubberduck's Code Explorer supports them.

2 with Rubberduck you can export the entire project in one step.

Upvotes: 3

Related Questions