I want to load base64 image gif to vba webbrowser control by html code, without writing a gif file in the computer.
Public Sub testUF()
Dim sBased64_Encoded As String
sBased64_Encoded = _
"R0lGODlhyADIAPIFAP%2FyAAoKCgAAAcRiAO0cJAAAAAAAAAAAACH%2FC05FVFNDQVBFMi4wAwEAAAAh%2BQQJCgAFAC" & _
"wAAAAAyADIAAAD%2F1i63P4wykmrvTjrzbv%2FYCiOZGmeaKqubOu%2BcCzPdG3feK7vfO%2F%2FwKBwSCwaj8ikcslsOp%2FQ" & _
"qHRKrVqv2Kx2y%2B16v%2BCweEwum8%2FotHrNbrvf8Lh8Tq%2Fb7%2Fi8fs%2Fv%2B%2F%2BAgYKDhIWGh4iJiouMjY6PkJGSk" & _
"5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq%2BwsbKztLW2t7i5uru8vb6%2FwMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna2" & _
"9zd3t%2Fg4eLj5OXmkwLpAszq68vt7OrI7QH1AfDD9Pb4wvr1%2FMH83ZP3S6C9gemAGdxH0NfCfw17PUTozqG6gwcBkph4EP" & _
"%2FSRI0jONrzeBEjxIQnRNYjmc7kyYolVAZgKcAlRRDt2gHYybPnzo6PPkbkkFOdz6MAgDoSitJD0XRIfSptxBQm0adRe05lpBMpS" & _
"Atds2bduiisz68VzIo9SlaRWp5oKbxdy7NtorkA4k7AS9cumKeAA9vMiNXr0L1G6a71%2ByWw45yDGRaNqtcBX8U%2FR555zLlm" & _
"ZIp4Kze4jJmxl86PP4NOfFQ0A9KKTWeReRCzbcNNI8C%2BLRsLbXu3g8M9bJm1cKS9r%2Fyudzy46N22k1tZHqD57efGrdfVbEam" & _
"VuDazxIvAF249NklI39nHr4n2vLBz%2FtOP3h99fbDc7%2FOjj%2Fzys3%2F9NlkX387vcdff%2FJtgVpL4PVnIFTHqQbHgp6x5%2BB4" & _
"8Nln04QL1kbggwI0J%2BEbFHp4oX4LZLhdZICYiJ9sZg0g4wD2MeJiezAaNyONK860y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ps9pGq169uLWL15w1n5VdgXZtu0ScEBhOgB7x4o21IqJte4Vw4" & _
"sahJ1fee3XzuTSORx%2F%2BkXp11sB%2FPOeOTvt078zDK4Gs0fIi97PU9818En7lwbuu52BP0b59UKX64cAfRP7hF586ZSyQDz0F5hWX" & _
"fF4siE6DjB3oWIIKSLgNhQ8iiKGGzXCYH4QYZkgfTwCSWOKAKPZU4gUsthggFjGiOOMVNT6l4ocnthjKjgnmeNON83HlY0AevtiAXzU1x" & _
"mRQnSkJwZN1fETlFqhJycCVXNLXpItaOtClkZhA2dOVYUoA1ZrqlZNmAWwmaaKcUb2JQZwXbtlmTnYqqB6ed7k1QgIAOw%3D%3D"
Dim sHTMLBody As String
sHTMLBody = "about:<html><body><img src='data:image/gif;base64," & sBased64_Encoded & "'></body></html>"
Dim o As New UserForm1
With o.Controls.Add("Shell.Explorer.2")
.Navigate2 sHTMLBody
End With
o.Show vbModeless
End Sub
The webbrowser shows
Cannot reach this page
The HTML code has been tested successfully if I put into html file and load in a browser.
Is it doable?
There's a limit to the length of a URL in IE (around 2k characters?) - try this instead.
'...
'...
Dim sHTMLBody As String
sHTMLBody = "<img src='data:image/gif;base64," & sBased64_Encoded & "'>"
Dim o As New UserForm1
With o.Controls.Add("Shell.Explorer.2")
.Navigate2 "about:blank"
While .readyState <> 4 Or .Busy: DoEvents: Wend
.document.Body.innerHTML = sHTMLBody
End With
o.Show vbModeless
...or using DOM methods
'...
'...
Dim imgSrc As String
imgSrc = "data:image/gif;base64," & sBased64_Encoded
Dim o As New UserForm1, img As Object
With o.Controls.Add("Shell.Explorer.2")
.Navigate2 "about:blank"
While .readyState <> 4 Or .Busy: DoEvents: Wend
Set img = .document.createElement("img")
img.src = imgSrc
.document.Body.appendChild img
End With
o.Show vbModeless
You could more-conveniently store your b64 string by pasting it into a worksheet somewhere...