Base64Doc

How to Decode and Encode Base64 Inside Microsoft Excel (Power Query & VBA)

Microsoft Excel has no built-in worksheet function named BASE64DECODE(), yet you can batch-convert text columns natively with zero macros using Power Query M formulas—as long as you respect Excel’s hard 32,767-character cell ceiling.

Zero-Macro Power Query Formulas: Binary.FromText & Binary.ToText

Decode and encode entire spreadsheet columns in modern Excel on Windows and macOS using built-in Power Query M expressions without enabling VBA macros.

Read full technical details

Analysts auditing ERP exports, webhook logs, or SKU token sheets frequently ask how to decode a Base64 column directly inside Excel without installing third-party COM add-ins. Since Excel 2016 and Microsoft 365 ship Power Query natively under Data -> Get Data -> From Table/Range, the built-in M library functions Binary.FromText and Binary.ToText handle RFC 4648 Base64 natively.

To encode a plain-text column into Base64, invoke Binary.ToText(Text.ToBinary([SourceText], TextEncoding.Utf8), BinaryEncoding.Base64). To decode a column back into readable text, normalize URL-Safe hyphens and underscores first, restore trailing = padding when length mod 4 is 2 or 3, and pass the result into Text.FromBinary(Binary.FromText(Padded, BinaryEncoding.Base64), TextEncoding.Utf8).

Because Power Query executes strictly inside Excel’s local data mashup engine without ActiveX controls, the exact same M query refreshes cleanly across corporate locked-down workstations.

The 32,767-Character Cell Trap & When to Use a Browser Workbook Viewer

Avoid silent data truncation caused by pasting encoded .xlsx workbooks or PDFs into Excel cells limited to 32,767 characters.

Read full technical details

Every individual Excel worksheet cell enforces an immutable ceiling of 32,767 characters. After accounting for Base64’s +33.33% size overhead, a single cell can hold at most roughly 24.5 KB of raw binary data. Attempting to paste a 100 KB Base64 string representing an entire multi-sheet .xlsx workbook or PDF invoice into cell A1 silently cuts off the remaining 75% of the payload.

This distinction separates two completely different Excel tasks: decoding short Base64 text fields stored inside spreadsheet rows (where Power Query excels), versus decoding a Base64-encoded .xlsx workbook returned by an API into an actual spreadsheet you can inspect.

Whenever an ERP or accounting API hands you a Base64 string representing a complete .xlsx or .csv workbook, paste that payload into Base64Doc’s /base64-to-excel workbench instead of a worksheet cell—decoding the PK\x03\x04 OOXML package locally with interactive sheet tabs and cell search.

VBA MSXML2, ADODB.Stream UTF-8 Safety & macOS Office Scripts Alternatives

Avoid VB6 UTF-16 garbling when writing VBA Base64 helpers on Windows and switch to TypeScript Office Scripts for cross-platform Microsoft 365.

Read full technical details

Legacy Windows automation workbooks often rely on VBA calling CreateObject("MSXML2.DOMDocument.6.0") with node.DataType = "bin.base64". A classic pitfall appears when converting the resulting Byte() array into a VBA String via StrConv(bytes, vbUnicode): VBA interprets bytes under the Windows ANSI codepage rather than UTF-8, scrambling Korean, Japanese, European accented characters, and emoji.

Pairing MSXML2 Base64 decoding with ADODB.Stream configured to Charset = "utf-8" (or writing binary arrays straight to disk with Open ... For Binary Access Write) preserves multi-byte characters accurately.

Keep in mind that macOS Excel blocks Windows COM/ActiveX objects such as MSXML2 and ADODB completely. For cross-platform workbooks shared across Windows, macOS, and Excel for the Web, move custom cell transforms into Power Query M or Microsoft 365 Office Scripts using standard TypeScript TextDecoder and Uint8Array logic.

Production Reference Code

// Power Query M custom column: safely decode UTF-8 Base64 strings (with URL-Safe & Data URI cleanup)
let
  RawInput = Text.Trim([Base64Column] ?? ""),
  WithoutPrefix = if Text.Contains(RawInput, ";base64,") then Text.AfterDelimiter(RawInput, ";base64,") else RawInput,
  Normalized = Text.Replace(Text.Replace(WithoutPrefix, "-", "+"), "_", "/"),
  PadCount = Number.Mod(4 - Number.Mod(Text.Length(Normalized), 4), 4),
  Padded = Normalized & Text.Repeat("=", PadCount),
  DecodedText = Text.FromBinary(Binary.FromText(Padded, BinaryEncoding.Base64), TextEncoding.Utf8)
in
  DecodedText

Step-by-Step Local Workflow

STEP 1

Separate Column Strings From Whole Files

Use Power Query for short Base64 text columns under 32,767 chars; send whole encoded .xlsx files straight to /base64-to-excel.

STEP 2

Load Table Into Power Query Editor

Select your data range and choose Data -> From Table/Range, then add a Custom Column under the Add Column tab.

STEP 3

Normalize URL-Safe & UTF-8 Encoding

Strip any data:*;base64, prefix, swap -/_ to +/, pad trailing =, and decode via Binary.FromText with TextEncoding.Utf8.

STEP 4

Close & Load Back to Worksheet

Verify decoded rows in Power Query Preview and click Close & Load to materialize clean columns inside Excel without macros.

Test Directly in Browser Workbench

Frequently Asked Questions

Does Microsoft Excel have a built-in BASE64DECODE or BASE64ENCODE worksheet formula?

No, Excel lacks a native worksheet cell formula for Base64, so you should use Power Query M functions (Binary.FromText and Binary.ToText), Office Scripts, or VBA MSXML2.

Why does pasting a Base64-encoded .xlsx or PDF string into an Excel cell break the file?

Excel caps every cell at 32,767 characters (~24.5 KB binary max), silently truncating larger Base64 payloads. Paste whole encoded workbooks directly into /base64-to-excel instead.

Does Power Query Binary.FromText work on macOS Excel without macros?

Yes, modern Microsoft 365 for Mac and Windows both support Power Query M Binary.FromText and Binary.ToText natively without VBA macro security warnings.

Why did my VBA MSXML2 Base64 macro turn UTF-8 accents or Asian text into mojibake?

StrConv(bytes, vbUnicode) decodes raw bytes using the local Windows ANSI codepage instead of UTF-8; route decoded bytes through ADODB.Stream with Charset="utf-8" instead.

How do I convert an existing Excel spreadsheet (.xlsx or .csv) into Base64 without VBA?

Drop the local .xlsx or .csv file onto Base64Doc /excel-to-base64 to encode all bytes locally in a Web Worker and copy JSON or code snippets.

Explore All 34 Base64 Converters & Developer Tools