Convert image (jpg) to base64 in Excel VBA?

I need to convert the image in Excel (or via VBA) to base64 (in the end I will draw the XML output).

How can i do this? Do I need to make a link to the DOM?

I read this question , but it only works for text strings, not images ...

Does anyone have a code that I can see?

+4
source share
2 answers

Here is the function. I can’t remember where I got it from.

Public Function EncodeFile(strPicPath As String) As String Const adTypeBinary = 1 ' Binary file is encoded ' Variables for encoding Dim objXML Dim objDocElem ' Variable for reading binary picture Dim objStream ' Open data stream from picture Set objStream = CreateObject("ADODB.Stream") objStream.Type = adTypeBinary objStream.Open objStream.LoadFromFile (strPicPath) ' Create XML Document object and root node ' that will contain the data Set objXML = CreateObject("MSXml2.DOMDocument") Set objDocElem = objXML.createElement("Base64Data") objDocElem.dataType = "bin.base64" ' Set binary value objDocElem.nodeTypedValue = objStream.Read() ' Get base64 value EncodeFile = objDocElem.Text ' Clean all Set objXML = Nothing Set objDocElem = Nothing Set objStream = Nothing End Function 
+7
source
0
source

All Articles