Function Base64Encode(inData As String) As String
Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim cOut As String, sOut As String, i As Long
Dim Bytes() As Byte
Dim t As String
Dim iLen As Long
Dim sGroup As String
t = StrConv(inData & "..", vbFromUnicode)
Bytes = t
iLen = UBound(Bytes) - 2
Bytes(iLen + 1) = 0
Bytes(iLen + 2) = 0
sOut = ""
For i = 0 To iLen Step 3
sGroup = Oct(&H10000 * CLng(Bytes(i)) + &H100 * CLng(Bytes(i + 1)) + Bytes(i + 2))
sGroup = String(8 - Len(sGroup), "0") & sGroup
sOut = sOut + Mid(Base64, CLng("&o" & Mid(sGroup, 1, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 3, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 5, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 7, 2)) + 1, 1)
Next
Select Case iLen Mod 3
Case 0:
sOut = Left(sOut, Len(sOut) - 2) + "=="
Case 1:
sOut = Left(sOut, Len(sOut) - 1) + "="
End Select
Base64Encode = sOut
End Function