Function does'nt work !!

MadameHugo

New Member
Joined
Feb 25, 2020
Messages
9
Office Version
  1. 2010
Platform
  1. Windows
Hi,

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? ...
 

Attachments

  • this.png
    this.png
    21.6 KB · Views: 18
It work's very good... Thank you for you efforts... but...

The format of base64 is very very long and when I import my file .xls into the website, it don't accept it because of the longer of bytes. Must i change something on the function Encode File ?
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
That is a different question
Please start a new thread for that question
Provide full information in your new thread in cluding the code you are currently using
 
Upvote 0
Hi,
Thank you for all your efforts, I will never forget that. I will start a new thread about that question.
 
Upvote 0
Try this
VBA Code:
Sub CallFunc()
    Dim cel As Range
    For Each cel In Range("B2:B6")
        cel.Offset(, 1) = EncodeFile(cel.Value)
    Next cel
End Sub

Hi Yongle !! When I tried to reproduce this code in house, i have this error, maybe it's the spaces ? In english it's : Arguments are of incorrect types, out of bounds, or in conflict with each other.
execute.png

And this the debug :

debug.png
 
Last edited:
Upvote 0
Sorry, I am unable to help you with that question
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top