Digitally Sign a VBA Code Project with Certificate

Digitally Sign a VBA Code Project with Certificate in Python

The following sample code illustrates how to make use of Workbook.vba_project.sign() method. Here are the input and output files of the sample code. You can use any excel file and any certificate to test this code.

from aspose.cells import Workbook
from aspose.cells.digitalsignatures import DigitalSignature
from datetime import datetime
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
password = "1234"
pfxPath = sourceDir + "sampleDigitallySignVbaProjectWithCertificate.pfx"
comment = "Signing Digital Signature using Aspose.Cells"
# Set Digital Signature
digitalSignature = DigitalSignature(open(pfxPath, "rb").read(), password, comment, datetime.now())
# Create workbook object from excel file
workbook = Workbook(sourceDir + "sampleDigitallySignVbaProjectWithCertificate.xlsm")
# Sign VBA Code Project with Digital Signature
workbook.vba_project.sign(digitalSignature)
# Save the workbook
workbook.save(outputDir + "outputDigitallySignVbaProjectWithCertificate.xlsm")