How to Decode Base64 in Excel (2 Suitable Examples)

 

 

Method 1 – Apply an Excel VBA Code for a HTML Decode String

Steps:

  • Go to the Developer tab from the ribbon.
  • Click on Visual Basic from the Code category to open the Visual Basic Editor. Or, press Alt + F11.

excel base64 decode

  • Click on Module from the Insert drop-down menu bar.

excel base64 decode

  • This will create a Module in your workbook.
  • Copy and paste the VBA code shown below into the module.

VBA Code:

Public Function HtmlDecode(StringToDecode As Variant) As String
    Set HFile = CreateObject("htmlfile")
    Set a = HFile.createElement("T")
    a.innerHTML = StringToDecode
    HtmlDecode = a.innerText
End Function
  • Press Ctrl + S to save the file.

excel base64 decode

  • Go back to the sample Excel sheet.
  • Insert the following formula into the result. Use your own cell reference for the source if you’re making a table from scratch.
=HtmlDecode(B5)
  • Press the Enter key.

  • Drag the Fill Handle icon down to duplicate the formula over the range or double-click on the plus (+) symbol.

  • You will see the results.

Read More: How to Change Encoding in Excel


Method 2 – Create a User Defined Function in Excel to Decode Base64

Steps:

  • Open a VBA Module (see Method 1 for instructions if needed).
  • Copy and paste the following VBA code into the module.

VBA Code:

Function Decoding(b64$)
    Dim i
    With CreateObject("Microsoft.XMLDOM").createElement("b64")
        .DataType = "bin.base64": .Text = b64
        i = .nodeTypedValue
        With CreateObject("ADODB.Stream")
            .Open: .Type = 1: .Write i: .Position = 0: .Type = 2: .Charset = "utf-8"
            Decoding = .ReadText
            .Close
        End With
    End With
End Function
  • Hit Ctrl + S.

excel base64 decode

  • Return to the Excel sheet now.
  • Put the following formula into the result cell, where the reference in the formula is the cell with the text you wish to decode:
=Decoding(B5)
  • Hit the Enter key.

NOTE: At the conclusion of a Base64 function, the equals sign (=) denotes padding. This is because the size of 8-bit strings and Base64 strings don’t match.
  • To copy the formula over the range, drag the Fill Handle symbol downward. Alternatively, double-click the plus (+) sign to AutoFill the range.

  • You can see the results.


How to Encode Base64 in Excel

Steps:

  • Access the Visual Basic Editor by pressing Alt + F11.
  • Pick the Module from the drop-down box under Insert.
  • Copy this code in the module.

VBA Code:

Function Encoding(text$)
    Dim i
    With CreateObject("ADODB.Stream")
        .Open: .Type = 2: .Charset = "utf-8"
        .WriteText text: .Position = 0: .Type = 1: i = .Read
        With CreateObject("Microsoft.XMLDOM").createElement("b64")
            .DataType = "bin.base64": .nodeTypedValue = i
            Encoding = Replace(Mid(.text, 5), vbLf, "")
        End With
        .Close
    End With
End Function
  • Save the file by pressing Ctrl + S on your keyboard.

excel base64 decode

  • Go back to the worksheet and insert the following formula in a cell where you want the code. The reference is the cell you want to encode.
=Encoding(B5)
  • Press the Enter key.

  • Drag the Fill Handle icon to copy the formula over the range or double-click on the plus (+) sign.


Things to Remember

  • While using VBA code make sure you save your file with the .xlsm extension.

Download the Practice Workbook

You can download the workbook and practice with it.


Related Articles


<< Go Back to Excel Encoding | Excel Files | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sabrina Ayon
Sabrina Ayon

Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo