In How to update modules automatically in VBA I showed how you could get code from github into VBA and set up a kind of .require approach to which classes, modules and references are needed. Let’s go through a step by step example, using the Automatic documentation procedures and adding them to a workbook.
Another way to do this would be to create an add-in, but here’s how I prefer to do it – this way you can update library code from this site online automatically from gists on github.
Here’s a post from the Excel Liberation blog with an even simpler example
Prepare your workbook.
Either create a new one, or use your existing workbook that you want to include the code in. Remember to trust access to the VBA project object model in the trust center. This is because we are going to automatically insert code into your workbook.
Add gistThat bootstrap to your workbook
This gets in the code needed to modify your workbook automatically. You can get that here, Just paste it in to a new module, by convention called gistThat_
Bring in required modules
The modules required for this class documenter are defined in XML files, stored as a GIST. You need to execute this in the gistThat_ module, passing the gist IDs of the XML files, as follows. It will also set up the necessary references. From time to time you can rerun this, to get any new versions of any libraries I release. That’s all that is needed.
Public Function gtExampleLoad()
' this is an example of how you would load your VBE with a particular manifest
' you could set the 2nd parameter to overrride conflict checking the first time used-
' we are going to need cDataSet and cjobject stuff as well
gtDoit "3414394", True
' this one loads the class serializer
gtDoit "5028829", True
End Function Now you can use the docProjects() sub of the classSerializer module to document your project. You can run gtUpdateAll() at any time to get the latest versions of all sources being managed by gistThat.
A note about virus false positives
Any code that can modify the VBA excel codebase has the capability of introducing nasty code into your workbook. By its nature (it pulls code off the internet and inserts it into your workbook), along with the fact you’ve allowed it to do it, this bootstrap can look like a potential virus to some virus checkers. once you’ve updated your workbook with the latest modules, I recommend you
- remove the gistthat module. You can always get it again here
- Turn back off trust to the VBA object model
- Run a virus scan on your workbook to reassure yourself you have followed these steps and not picked up any malware.