Convert image jpg to base64 in Excel VBA

0 votes
I want to base64 encode an image inside of Excel (or using VBA) (in the end I will make XML output).

How can I go about this? Do I need to refer to the DOM?
Sep 26, 2022 in Others by Kithuzzz
• 38,000 points
3,082 views

1 answer to this question.

0 votes

Heres a function. 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
answered Sep 27, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Convert a single png file to jpg in vba

Try this code: Sub ConveretPNGToJpg() ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 63,600 points
1,581 views
0 votes
1 answer

How do I insert a WebP-image (".jpg") in Excel using VBA?

It's not currently on the list of ...READ MORE

answered Nov 15, 2022 in Others by narikkadan
• 63,600 points
764 views
0 votes
1 answer

Convert excel file to jpg in c#

You can use Aspose : http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/category1129.aspx For example : http://www.aspose.com/docs/display/cellsnet/Converting+Worksheet+to+Image Sample ...READ MORE

answered Dec 27, 2022 in Others by narikkadan
• 63,600 points
1,242 views
0 votes
1 answer

Language independent way to get "My Documents" folder in VBA Excel 2003

 Hello :)  This code may help you in your ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
821 views
0 votes
1 answer
0 votes
1 answer

Sending excel data to Tally

You can use Requests to send the ...READ MORE

answered Nov 19, 2022 in Others by narikkadan
• 63,600 points
914 views
0 votes
1 answer

How can I preserve the format while exporting data from excel to evernote

The contents for an Evernote note are ...READ MORE

answered Jan 5, 2023 in Others by narikkadan
• 63,600 points
1,108 views
0 votes
1 answer

Create numbered XML nodes, set attributes when creating XML node

Just like createElement, createAttribute is a method of the xml ...READ MORE

answered Feb 20, 2023 in Others by Kithuzzz
• 38,000 points
1,168 views
0 votes
1 answer

Convert table in a jpg image to excel using python

I believe you must execute OCR (optical ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 63,600 points
2,285 views
0 votes
1 answer

Convert image (jpg, png, jpeg) to base64

Try this - it will perform the ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
1,269 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP