Knowledge Base
How to Apply a Digital Signature to a VBA Project in Microsoft Office
Overview
By the end of this article, you will have applied a code signing certificate to a Visual Basic for Applications (VBA) project so that Microsoft Office identifies your macros as trusted and unaltered. The article first defines what a VBA digital signature is, then lists the prerequisites you need — a code signing certificate and the Developer tab. It then walks through eight steps performed in the Visual Basic Editor (VBE), the built-in code window where VBA projects are opened and signed. It closes with verification, troubleshooting for the most common signing failures, and answers to related questions.
What is a VBA digital signature?
A Visual Basic for Applications (VBA) digital signature is a cryptographic stamp applied to a macro project using a code signing certificate. The signature identifies the publisher of the macro and proves the code has not been modified since it was signed. When a user opens a signed file, Microsoft Office checks the signature and can allow the macro to run without the standard security warning, provided the publisher is trusted. Without a signature, Office treats the macro as an unknown publisher and blocks or warns on it by default.
Similar questions
- How do I sign an Excel macro with a code signing certificate?
- What are the steps to digitally sign a VBA project in Word?
- Why does Office say my macro is from an unknown publisher?
- How do I stop the macro security warning for my own macros?
VBA code signing setup in Microsoft Office
Prerequisites
Before signing a Visual Basic for Applications (VBA) project, confirm you have the following:
- A valid code signing certificate installed on your computer or on a hardware token.
- The Microsoft Office file (Word, Excel, or another Office application) that contains the VBA project you want to sign.
- The Developer tab enabled in that Office application. Step 2 below explains how to enable it.
- Write access to save the file after signing.
Steps to sign a VBA project
Each step below is performed in the Microsoft Office application that contains your Visual Basic for Applications (VBA) project. Steps 3 to 7 take place in the Visual Basic Editor (VBE), the code window built into Office.
Step 1 — Open the file containing your macro
Open the Microsoft Office file (for example, an Excel workbook or a Word document) that contains the VBA project you want to sign. Signing is applied per file, so open the specific file you intend to distribute.
Step 2 — Enable the Developer tab
If the Developer tab is not already visible on the ribbon, select File, then Options, then Customize Ribbon, select the Developer check box, and select OK. The Developer tab now appears on the ribbon.
Step 3 — Open the Visual Basic Editor
On the Developer tab, select Visual Basic, or press Alt + F11. The Visual Basic Editor (VBE) opens in a separate window.
Step 4 — Select your VBA project
In the Project Explorer pane on the left side of the Visual Basic Editor (VBE), select the VBA project you want to sign. If the Project Explorer pane is not visible, press Ctrl + R to display it.
Step 5 — Open the Digital Signature window
On the Visual Basic Editor (VBE) menu bar, select Tools, then Digital Signature. A dialog box opens and displays the current signature status of the selected project. If the project has never been signed, the status reads [No certificate].
Step 6 — Choose your certificate
In the Digital Signature dialog box, select Choose. A list of digital certificates installed on your computer or token appears. Select the code signing certificate you installed, then select OK. The certificate name now appears as the signing certificate for the project.
Step 7 — Apply the signature
Select OK again in the Digital Signature dialog box. Office applies the signature to the VBA project.
Step 8 — Save your file
Save the Microsoft Office file. The digital signature is embedded in the file only when the file is saved. The VBA project is now digitally signed.
How to verify the signature was applied
To confirm that the VBA project was signed successfully:
- In the Visual Basic Editor (VBE), select Tools, then Digital Signature.
- Confirm that your code signing certificate is listed as the current signature for the project, rather than [No certificate].
- Open the saved file on a different computer and confirm that Microsoft Office identifies the macro as digitally signed and names your publisher in the security notice.
If the certificate name is displayed in the Digital Signature dialog box after reopening the file, the signature was applied and saved correctly.
Troubleshooting
Issue: The certificate does not appear in the Choose list.
Cause: The code signing certificate is not installed in the current user's personal certificate store, or the hardware token is not connected.
Solution: Connect the token if one is used, then confirm the certificate is present under Certificates – Current User → Personal → Certificates. Install or import the certificate for the same Windows user account that is running Microsoft Office.
Issue: The signature disappears after the file is closed and reopened.
Cause: The file was not saved after the signature was applied, or it was saved in a format that does not retain macros.
Solution: Reapply the signature, then save the file in a macro-enabled format such as .xlsm, .docm, or .xlsb.
Issue: Office still shows the macro as coming from an unknown publisher.
Cause: The signature is present, but the publisher has not been added to the recipient's Trusted Publishers list.
Solution: On the recipient machine, open the macro security notice and select the option to trust all documents from this publisher, or have an administrator distribute the certificate to Trusted Publishers by policy.
Issue: The project shows as signed but the signature is marked invalid.
Cause: The VBA code was edited after signing, or the signing certificate has expired.
Solution: Reapply the signature after any code change. If the certificate has expired, sign with a current code signing certificate.
Frequently asked questions
What is a code signing certificate?
A code signing certificate is a digital certificate issued to a verified individual or organization that is used to sign software and macros. It binds the publisher's identity to the signed code so that recipients can confirm both who published it and that it has not been altered.
Do I need to re-sign the project after editing the macro?
Yes. Any change to the Visual Basic for Applications (VBA) code invalidates the existing signature. Reapply the signature and save the file again before distributing it.
Can I sign a VBA project without a code signing certificate?
You can create a self-signed certificate using the SelfCert tool included with Microsoft Office, but it is only trusted on the machine where it was created. For files distributed to other users, use a code signing certificate issued by a certificate authority.
Does signing the VBA project also sign the document contents?
No. Signing in the Visual Basic Editor (VBE) applies only to the macro project. Signing the document itself is a separate action performed from the Office application's Info screen.
Which Office applications support VBA project signing?
The Digital Signature option is available in Office applications that include the Visual Basic Editor (VBE), including Word, Excel, PowerPoint, Outlook, and Access on Windows.
Related articles
Need assistance?
Contact our team for help with your purchase or issuing your certificate.