MadameHugo
New Member
- Joined
- Feb 25, 2020
- Messages
- 9
- Office Version
- 2010
- Platform
- Windows
Hi,
After many researches, I used this function to convert my images path into format BASE64.
But when i call this function like : =EncodeFile(G2)
NOTE : G2 that contain the PATH OF IMAGE : C:\Users\dalila\Pictures\images\naom_59dddfc7dd0b0.jpg
I have the result "#VALUE!"
Can you help me please? ...
After many researches, I used this function to convert my images path into format BASE64.
VBA Code:
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
But when i call this function like : =EncodeFile(G2)
NOTE : G2 that contain the PATH OF IMAGE : C:\Users\dalila\Pictures\images\naom_59dddfc7dd0b0.jpg
I have the result "#VALUE!"
Can you help me please? ...