What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 31405 |  Welcome, Guest!   Register  Login
Home > Articles > Error and Resolution > VBA - Digital Certificate Issue

VBA - Digital Certificate Issue

Article posted by Ambily.Raj on 9/26/2012 | Views: 1424 | Category: Error and Resolution | Level: Intermediate | Points: 250 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.

 

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Ambily KK

Experience:9 year(s)
Home page:http://ambilykk.com/
Member since:Tuesday, May 18, 2010
Level:Silver
Status: [Member] [Microsoft_MVP] [MVP]
Biography: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.
>> Write Response - Respond to this post and get points
Related Posts

Errors And Resolution encountered by Programmers in their daily life

Many times we came across in debugging legacy applications built on ASP and COM. Debugging of legacy applications are error prone and complex.

I always Blog about the Errors i got that are no Common, but i realised that few people might know about my Bloggs, so i decided to write an Article based on the Error and Solution from uncommon errors in the Programming World.

This article tries to troubleshoot the error: An attempt to attach an auto-named database for file <C:\database file path> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. This article tells the step by step procedure to handle this type of error.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 6:21:53 PM