Here's a module for calculating SHA1 hashes that is usable for Excel formulas eg. To use it, make a new module called 'module_sha1'. Code Listings. The VBA code below generates the digests for the MD5, SHA1, SHA2-256, SHA2-384, and SHA2-512 hashes, for strings, in either of the hex or base-64 output formats. These codings each make use of MS Office's built-in functions, and provide consistent results. It has been noted that original implementations elsewhere for.
Here's a module for calculating SHA1 hashes that is usable for Excel formulas eg. To use it, make a new module called 'modulesha1' and copy and paste it all in. This is based on some VBA code from, with changes to support passing it a string, and executable from formulas in Excel cells. These days, you can leverage the.NET library from VBA.
The following works for me in Excel 2016. Returns the hash as uppercase hex. Public Function SHA1(ByVal s As String) As String Dim Enc As Object, Prov As Object Dim Hash As Byte, i As Integer Set Enc = CreateObject('System.Text.UTF8Encoding') Set Prov = CreateObject('System.Security.Cryptography.SHA1CryptoServiceProvider') Hash = Prov.ComputeHash2(Enc.GetBytes4(s)) SHA1 = ' For i = LBound(Hash) To UBound(Hash) SHA1 = SHA1 + Hex(Hash(i) 16) + Hex(Hash(i) Mod 16) Next End Function.