+ Reply to Thread
Results 1 to 10 of 10

Image path

Hybrid View

me_king Image path 05-28-2012, 01:09 PM
JosephP Re: Image path 05-28-2012, 05:20 PM
me_king Re: Image path 05-29-2012, 07:03 AM
JosephP Re: Image path 05-29-2012, 10:17 AM
me_king Re: Image path 05-29-2012, 06:42 PM
JosephP Re: Image path 05-30-2012, 05:03 AM
me_king Re: Image path 05-30-2012, 08:53 PM
me_king Re: Image path 05-31-2012, 06:35 AM
me_king Re: Image path 05-31-2012, 06:52 AM
JosephP Re: Image path 05-31-2012, 06:56 AM
  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Image path

    Quote Originally Posted by JosephP View Post
    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.
    Appreciate your time and effort...will let you know how it goes....

  2. #2
    Registered User
    Join Date
    04-12-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Image path

    Quote Originally Posted by me_king View Post
    Appreciate your time and effort...will let you know how it goes....
    Image but with an "x" i mean invalid image, the file gets saved and i have checked the path is also correct. Don't know for some reason its not showing the image.

  3. #3
    Registered User
    Join Date
    04-12-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: Image path

    Quote Originally Posted by me_king View Post
    Image but with an "x" i mean invalid image, the file gets saved and i have checked the path is also correct. Don't know for some reason its not showing the image.
    Yes it worked but what I did is that I saved the image and then used the same path to refer to it, used piccode function and removed the other ones...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1