Encode and Decode Base64 Within MS Excel

Did someone hand you a large amount of data in an Excel spreadsheet encoded in base64?  Or do you have data in an Excel sheet that you need converted to base64? No problem!

Side note: This page has another way to do it with a project reference to a Microsoft XML library.  However, we're going to do it our own way, so you can see the entire code.

We're going to use a vb module written by Christian d'Heureuse.  It's available here  (go ahead and download Base64Coder.bas - it's licensed under the GNU/LGPL license).  Open Excel, then record a macro.  Then view and edit that macro.  A Microsoft Visual Basic editor should open.  On the left side is a folder of Modules.  Right click on the folder, and import the Base64Coder.bas file you downloaded from Christian's website.  Go ahead and read through it if you like.

Now in your own module (the one containing your recorded macro), put these two macros:

Sub DecodeBase64()
 For Each cell In Selection
 cell.Value = Base64DecodeString(cell.Value)
End Sub
Sub EncodeBase64()
 For Each cell In Selection
 cell.Value = Base64EncodeString(cell.Value)
End Sub


Save, and go back to your Excel sheet.  Now you can select the cells you'd like to convert, and run the "DecodeBase64" and "EncodeBase64" macros as needed.  If you don't want to go through all the setup process, here's an Excel spreadsheet already set up for you.  Enjoy!

Comments (5) Trackbacks (0)
  1. Thank you for this macro!

  2. Hi,
    Thanks for the macro. I have downloaded the spread sheet but I get the below error when I run the macro.
    Length of base64 encoded input string is not a multiple of 4.

    I am trying to decode the below data.

  3. Thank you so much for posting this. You saved me from a long night of figuring out how to encrypt a batch of text that was dumped on me at the last minute. You rock!

  4. Thank You. Just type in EXCEL =Base64EncodeString(Your CELL) or =Base64DecodeString(Your CELL).

  5. Great !!! working like a charm. . .

    Thanks for the attachment .

Cancel reply

No trackbacks yet.