+ Reply to Thread
Results 1 to 4 of 4

Need Help-Add Image to a hyperlink

Hybrid View

Ashish82 Need Help-Add Image to a... 06-28-2008, 06:52 PM
shg Ashish, I'm sure when... 06-28-2008, 07:38 PM
Ashish82 Need Help- Add Image to a... 06-28-2008, 09:20 PM
shg Thank you, Ashish82. 06-29-2008, 06:09 PM
  1. #1
    Registered User
    Join Date
    06-19-2008
    Posts
    10

    Need Help-Add Image to a hyperlink

    Hi,

    I have a macro created by Leith Ross that extracts the name of the file and creates its hyperlink in different columns according to its extension like jpg, pdf etc. I need io replace the hyperlink with a image i.e instead of showing the full path of hyperlink , it should display any image and if I click on that image it should open the respective file. You can see previous thread through the link :
    http://www.excelforum.com/showthread.php?t=647491

    here is the code by Leith Ross:

    Sub ListFilesAndHyperlinks()

    Dim C As Variant
    Dim FileDir As Variant
    Dim FileExt As String
    Dim FileName As String
    Dim FSO As Object
    Dim NamePos As Variant
    Dim PrevFile As String
    Dim R As Long

    FileDir = InputBox("Input the path containing the files you " & _
    "want to list on your worksheet" & vbCrLf & vbCrLf & _
    "for example:C:\Microarray")

    If FileDir = "" Then Exit Sub

    If Right(FileDir, 1) <> "\" Then
    FileDir = FileDir & "\"
    End If

    R = 1 'Start listing at row 2. Headers in row 1
    Set FSO = CreateObject("Scripting.FileSystemObject")

    For Each F In FSO.GetFolder(FileDir).Files
    FileName = Split(F.Name, ".")(0)
    FileExt = FSO.GetExtensionName(F)
    FP = F.Path
    Select Case FileExt
    Case Is = "jpg"
    C = "C": GoSub AddLink
    Case Is = "pdf"
    C = "D": GoSub AddLink
    End Select
    Next F

    Set FSO = Nothing
    Exit Sub

    AddLink:
    If FileName <> PrevFile Then R = R + 1
    Cells(R, C).Hyperlinks.Add Anchor:=Cells(R, C), Address:=F.Path
    NamePos = Split(FileName, "_")
    Cells(R, "A") = NamePos(0)
    On Error Resume Next
    Cells(R, "B") = NamePos(1)
    Err.Clear
    PrevFile = FileName
    Return

    End Sub


    I need to modify the code to add image to a hyperlink .

    Thanks

    Ashish

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Ashish,

    I'm sure when Leith posted his code, he used Code Tags. Please edit your post to do so.

  3. #3
    Registered User
    Join Date
    06-19-2008
    Posts
    10

    Need Help- Add Image to a hyperlink

    Hi,

    There was no edit option, so I am posting the thread again.
    I have a macro created by Leith Ross that extracts the name of the file and creates its hyperlink in different columns according to its extension like jpg, pdf etc. I need io replace the hyperlink with a image i.e instead of showing the full path of hyperlink , it should display any image and if I click on that image it should open the respective file. You can see previous thread through the link :
    http://www.excelforum.com/showthread.php?t=647491

    here is the code by Leith Ross:
    Sub ListFilesAndHyperlinks()
    
    Dim C As Variant
    Dim FileDir As Variant
    Dim FileExt As String
    Dim FileName As String
    Dim FSO As Object
    Dim NamePos As Variant
    Dim PrevFile As String
    Dim R As Long
    
    FileDir = InputBox("Input the path containing the files you " & _
    "want to list on your worksheet" & vbCrLf & vbCrLf & _
    "for example:C:\Microarray")
    
    If FileDir = "" Then Exit Sub
    
    If Right(FileDir, 1) <> "\" Then
    FileDir = FileDir & "\"
    End If
    
    R = 1 'Start listing at row 2. Headers in row 1
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    For Each F In FSO.GetFolder(FileDir).Files
    FileName = Split(F.Name, ".")(0)
    FileExt = FSO.GetExtensionName(F)
    FP = F.Path
    Select Case FileExt
    Case Is = "jpg"
    C = "C": GoSub AddLink
    Case Is = "pdf"
    C = "D": GoSub AddLink
    End Select
    Next F
    
    Set FSO = Nothing
    Exit Sub
    
    AddLink:
    If FileName <> PrevFile Then R = R + 1
    Cells(R, C).Hyperlinks.Add Anchor:=Cells(R, C), Address:=F.Path
    NamePos = Split(FileName, "_")
    Cells(R, "A") = NamePos(0)
    On Error Resume Next
    Cells(R, "B") = NamePos(1)
    Err.Clear
    PrevFile = FileName
    Return
    
    End Sub
    I need to modify the code to add image to a hyperlink .

    Thanks

    Ashish

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Thank you, Ashish82.

+ 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