Give this a try. I wrote two functions DecodeBase64
and WriteByteArrayToFile
. DecodeBase64
takes in a Base64 encoded string and returns the Byte()
from this. WriteByteArrayToFile
takes in a Byte()
and a FilePath as string, and will write this Byte()
to a file.
Update this section "YOURPATHGOESHERE\Picture.png"
in the Example
Sub to a valid file path on your computer, see if this code does what you are after. I'm getting a very small picture of what appears to be a square when running the code below.
Code
Option Explicit
'Decode Base64 string into a byte array
Public Function DecodeBase64(ByVal Base64String As String) As Byte()
With CreateObject("MSXML2.DOMDocument").createElement("b64")
.DataType = "bin.base64"
.Text = Base64String
DecodeBase64 = .nodeTypedValue
End With
End Function
'Take a byte array and write to a file
Public Sub WriteByteArrayToFile(FileData() As Byte, ByVal FilePath As String)
Dim FileNumber As Long: FileNumber = FreeFile
Open FilePath For Binary Access Write As #FileNumber
Put #FileNumber, 1, FileData
Close #FileNumber
End Sub
'Run from here
Sub example()
WriteByteArrayToFile DecodeBase64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII="), "YOURPATHGOESHERE\Picture.png"
End Sub