Thursday, October 29, 2009

Office VBA: Installing Self-signed Digital Certificates

First you need to create a self-signed digital certificate by going to Start > Programs > Microsoft Office > Microsoft Office Tools > Digital Certificate For VBA Projects (this is actually a shortcut to %PROGRAMFILES%Microsoft OfficeOFFICE11SELFCERT.EXE).

 

Next, you need to sign your VBA code project in the VBA IDE by going to the Tools menu > Digital Signature... and pressing "Choose" to choose the certificate you created above.

 

So far, this is relatively straightforward.  The problems come when you're trying to re-install certificates after an OS re-install.  Or trying to install certificates on someone else's machine.  Here are some clues I've found:

 

1. The actual certificate files are stored in %APPDATA%MicrosoftSystemCertificatesMy

 

2. There's a snap-in called Certmgr.msc which helps you manage certificates.  You want to drag your self-signed certificate into the Trust Root Certification Authorities > Certificates folder.

3. When you open a MS Office file that has signed code in it, you want to try to "View Certificate" and "Install Certificate" if you can.  Or "Always Trust Macros From This Publisher".  Here is a good link on some resources to help you.

 

I'll continue to be on the lookout for more information about backing up and restoring certificates before and after a machine reinstall.