+ 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

    Image path

    I have an image in excel which i want to use as a hyperlink image. The link is sent to all users through mail. I can send hyperlinks but what I want is that the image to be the hyperlink , something like this :
    "<br>" & "<a href=" & Replace(url, " ", "%20") & "> <img src=" & picture1 & " alt=" & "timer.GIF" & "/></a>"

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Image path

    if the image isn't stored somewhere everyone can access it I think you'll have to encode the file into base64 and embed that string into the source. you may need to save the file to disk before you can do that.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  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 JosephP View Post
    if the image isn't stored somewhere everyone can access it I think you'll have to encode the file into base64 and embed that string into the source. you may need to save the file to disk before you can do that.
    I just want to insert the image into the html tag mentioned above. I tried using names but i think html tags cant read that so i have to specify the path of that image..

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Image path

    the image does not have a path unless you extract it from the container file (if it's an openxml format file) and specifying a local path won't help since nobody else will be able to access it.

  5. #5
    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
    the image does not have a path unless you extract it from the container file (if it's an openxml format file) and specifying a local path won't help since nobody else will be able to access it.
    So is there any way i can specify the img src tag in html to take the image in excel. Actually I am sending the link of a file path to all users through outlook... and its automated. So for the body of the outlook i have that html coding.... Earlier i used to simply sent the hyperlink but now i want the image to be the hyperlink. Could it be done...

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Image path

    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.

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

  8. #8
    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.

  9. #9
    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...

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Image path

    since I don't know what you were doing with the output I can't comment. I tested the code by pasting the output into an htm file and that loaded the image perfectly in IE.

+ 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