you can write the file to disk then encode it and embed that data using code like this
Function GetPicCode(shp As Shape, sPath As String) As String
Dim oPic As Object
Dim cht As Chart
Dim shp As Shape
With shp
Set cht = .Parent.Shapes.AddChart(Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height).Chart
.CopyPicture xlScreen, xlPicture
End With
cht.Paste
cht.Export sPath, "GIF"
cht.Parent.Delete
GetPicCode = Base64Encode(sPath)
End Function
Function Base64Encode(strFilePath As String)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.DataType = "bin.base64"
oNode.nodeTypedValue = FileToBinary(strFilePath)
Base64Encode = oNode.Text
Set oNode = Nothing
Set oXML = Nothing
End Function
Function FileToBinary(strFilePath As String)
'Create Stream object
Dim BinaryStream As Object
Const adTypeBinary As Long = 1
Set BinaryStream = CreateObject("ADODB.Stream")
With BinaryStream
.Type = adTypeBinary
.Open
.LoadFromFile strFilePath
FileToBinary = .Read
End With
Set BinaryStream = Nothing
End Function
which you call with this
Dim sBody as string
Dim sPicPath as string
sPicPath = ThisWorkbook.Path & "\Temp.gif"
sBody = "<br><a href=" & Replace(url, " ", "%20") & "> <img src=""data:image/gif;base64," & GetPicCode(activesheet.shapes("Picture 1"), sPicPath) & """ alt=""timer.GIF""/></a>"
as an example.
Bookmarks