VBA - Digital Certificate Issue

Ambily.Raj
Posted by in Error and Solution category on for Intermediate level | Points: 250 | Views : 7303 red flag

When we work on a Macro enabled excel file with digital certificate, most of us faced the issue - “There was a problem with the digital certificate. The VBA project could not be signed. The signature will be discarded”. Today we will look a little deeper into the issue.

Problem

When trying to save the excel after  assigning a digital certificate to the VBA project , receiving the following exception
“There was a problem with the digital certificate. The VBA project could not be signed. The signature will be discarded”.

 


Repro the issue:

1. Launch the Visual Studio Command prompt
                Start -> All Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools

                -> Visual Studio Command Prompt


2. Create the certificate authority using the makecert
            makecert -n "CN=TestCA" -cy authority -a sha1 -sv "TestCAPK.pvk" -r "TestCA.cer"
            Specify the password. "Sample@123".
 
2. Create the certificate
            makecert -n "CN=TestCA"  -ic "TestCA.cer" -iv "TestCAPK.pvk" -a sha1 -sky signature

           -sv "TestTestPK.pvk" "TestTestCert.cer"
            Specify the password. "Test@123"
 
3. Now combine the private key and certificate to pfx file
            pvk2pfx -pvk "TestTestPK.pvk" -spc "TestTestCert.cer" -pfx "TestTestCert.pfx" -pi Test@123
 
Now open the certificate store and import the certificate "TestTestCert.cer" into Personal node. Remember the digital certificates appearing under the VBA editor window is from Personal node only.
 
Now, try to use the certificate in your Macro.
 
1.     Open Excel sheet
2.     Click on Developer Tab
3.     Select Visual Basic under Code section



 
4.     Enter the Macro Code in Microsoft Visual basic for Applications windows

 
 
5.     Now, select the Digital Signature option from Tools menu.

 
 
6.     This will open the Digital Signature Window. Select Choose to Select new certificate

 


 
 
7.     Select our certificate from the Select a Certificate window.

 

 


 
8.     Click OK
9.     Click OK in Digital Signature Window.
10.  Now Save the Macro enabled Excel. This will throw the exception



Solution

Now, go back to the certificate store and import the pfx file into Personal node.
Open the VBA editor window from the Excel sheet and try to sign using the Digital Signature. This time excel will save successfully.

 

Page copy protected against web site content infringement by Copyscape

About the Author

Ambily.Raj
Full Name: Ambily KK
Member Level: Silver
Member Status: Member,Microsoft_MVP,MVP
Member Since: 5/18/2010 1:05:25 AM
Country: India
Thanks Ambily K K http://ambilykk.com/
http://ambilykk.com/
I have over 9 years of experience working on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Office Open XML, Azure, Visual Studio 2010. Technology adoption and learning is my key strength and technology sharing is my passion.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)