在Excel VBA中将图像(jpg)转换为base64?

我需要将Excel (或通过VBA) 内的图像转换 为base64 (最终我将输出XML)。

我怎样才能做到这一点? 我是否需要对DOM进行引用?

我一直在阅读这个问题,但它只适用于文本string而不是图像…

有没有人有我能看到的任何代码?

这是一个函数。 不记得我从哪里得到它。

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 

请看看这里: Base64编码和解码文件

编辑:看看http://pastebin.com/f2a199d30