5

NOTE: This is not a duplicate because I am asking about signing code, not the document body.

On a regular basis we need to update the certificates used to sign the code in a whole pile of Microsoft Word documents. This could be in conjunction with updating the VBA code itself.

To be clear, I want to sign the code/macros in the document so they can run. My intention is not to sign the document body. See: http://support.microsoft.com/kb/920627, for the difference.

We have built a utility using C# that allows us to update the VBA code, references and many other aspects of these templates but we have never found a good way to update the certificate.

Our code has access to the following name spaces.

using Microsoft.Office.Interop.Word
using Microsoft.Vbe.Interop;
using Microsoft.Office.Core;

Our current solution using SendKeys is fragile and just plain unacceptable.

AnthonyVO
  • 3,821
  • 1
  • 36
  • 41
  • 1
    @nl-x: yeah, ok, i might have giggled too, except that I'm more apt to chuckle, and except that I'm at work, and chuckling at [so] posts isn't considered a reason to bill my customer... – John Saunders May 14 '14 at 20:18
  • 1
    Can you post the snippet with SendKeys? How are you signing them? This [SO Question](http://stackoverflow.com/questions/12258106/digitally-signing-a-docx-with-no-need-to-open-the-document-with-c-sharp) may be relevant – Jimmy Smith May 14 '14 at 20:21
  • Autohotkey is a better solution than sendkeys, in my experience, though this is still a hack at best. – enderland May 14 '14 at 20:41
  • Looks like this has been asked before : http://stackoverflow.com/questions/1480050/is-there-a-way-to-programmatically-add-a-digital-signature-to-a-vba-macro-in-a-w . The solution you propose is a variant of what everybody else that has posted an answer online outside of SO has said to do. It's hack and sucks, but works. – Semicolons and Duct Tape May 14 '14 at 21:57
  • @JohnSaunders, After following your pointer I realized that it was about signing the document body as a whole instead of signing the code. I have clarified my question. – AnthonyVO May 15 '14 at 17:27
  • @ClaytonDavis, That question was asked nearly 5 years ago. I am really hoping there is a better answer now. – AnthonyVO May 15 '14 at 17:33
  • @AnthonyVO not that I am aware of / saw. I ran across a couple of sites with people trying to do this on MS knowledge base and Google groups. they all were doing a variation of what you were, and wanting a better solution to no avail. I spent some time trying to do it in Word 2013 just to double check and if you can do it now I don't see how because the add method for signatures seems to always launch the prompt, which has dimmed my hopes for finding a truly programmatic solution. If you find a way though I am interested in the technical details, and wish you the best. – Semicolons and Duct Tape May 16 '14 at 13:59

0 Answers0