+ Reply to Thread
Results 1 to 5 of 5

Auto hyperlink to files from list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Auto hyperlink to files from list

    Good morning folk

    I have the code below to create a list of files in a folder on a sheet,,,,, is there a way to automatically have the file names hyperlinked to the files

    Many thanks

    JT
    Dim iRow
    
    Sub ListFiles()
        iRow = 6
        Call ListMyFiles(Range("C1"), Range("D1"))
    End Sub
    
    Sub ListMyFiles(mySourcePath, IncludeSubfolders)
        Set MyObject = New Scripting.FileSystemObject
        Set mySource = MyObject.GetFolder(mySourcePath)
        On Error Resume Next
        For Each myFile In mySource.Files
            iCol = 2
            Cells(iRow, iCol).Value = myFile.Path
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.Name
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.Size
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.DateLastModified
            iRow = iRow + 1
        Next
        If IncludeSubfolders Then
            For Each mySubFolder In mySource.SubFolders
                Call ListMyFiles(mySubFolder.Path, True)
            Next
        End If
    End Sub
    Last edited by JamesT1; 09-01-2014 at 03:41 AM.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Auto hyperlink to files from list

    See if this is something you can work with:
    Sub ConvertTxt2Hyperlink()
    Dim cCell As Range
    
    For Each cCell In selection.Cells
    
       If cCell.Hyperlinks.Count = 0 Then
          On Error Resume Next
          ActiveSheet.Hyperlinks.Add _
             Anchor:=cCell, _
             Address:=cCell.Value, _
             TextToDisplay:=cCell.Value
       End If
    Next cCell
    End Sub
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Re: Auto hyperlink to files from list

    Ron

    many thanks for your help..... with one exception the code is doing as it should..... it is producing the list and creating a hyperlink from each file name..... however it is hyperlinking to the folder where the sheet containing the code and list is kept,,, not the folder where the files are stored........

    I've been trying to adjust and figure it our myself,, but I'm not having any luck

    JT

    Dim iRow
    
    Sub ListFiles()
        iRow = 6
        Call ListMyFiles(Range("C1"), Range("d1"))
    End Sub
    
    Sub ListMyFiles(mySourcePath, IncludeSubfolders)
        Set MyObject = New Scripting.FileSystemObject
        Set mySource = MyObject.GetFolder(mySourcePath)
        Dim cCell As Range
        
        On Error Resume Next
        For Each myFile In mySource.Files
            iCol = 2
            Cells(iRow, iCol).Value = myFile.Path
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.Name
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.Size
            iCol = iCol + 1
            Cells(iRow, iCol).Value = myFile.DateLastModified
            iRow = iRow + 1
        Next
        If IncludeSubfolders Then
            For Each mySubFolder In mySource.SubFolders
                Call ListMyFiles(mySubFolder.Path, True)
            Next
        End If
    
    For Each cCell In Range("C6:c500").Cells
    
       If cCell.Hyperlinks.Count = 0 Then
          On Error Resume Next
          ActiveSheet.Hyperlinks.Add _
             Anchor:=cCell, _
             Address:=cCell.Value, _
             TextToDisplay:=cCell.Value
       End If
    Next cCell
    End Sub
    Last edited by JamesT1; 08-31-2014 at 03:21 PM.

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Auto hyperlink to files from list

    The code I posted uses the exact contents of the referenced cell to create a hyperlink.

    Do you have an entry in the Hyperlink Base settings?
    File.Properties
    ...Hyperlink Base -> enter the default hyperlink location here
    
    Note: If Hyperlink Base does not display
    ...click: Show More Properties

  5. #5
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Re: Auto hyperlink to files from list

    Ron....

    That was the problem...... many thanks for your help.... very much appreciated......

    JT

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Use VBA to auto Hyperlink files based on input
    By zulfaizan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-13-2014, 03:52 AM
  2. [SOLVED] List All Changed Excel Files Today On Drive And Hyperlink (Incl. Subfolders)
    By alienware in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2014, 03:18 AM
  3. Click on a hyperlink to another sheet and auto filter from dropdown list
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-24-2013, 02:34 AM
  4. Auto hyperlink to files???
    By mickey331 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-17-2011, 03:30 AM
  5. [SOLVED] Look up actual files from a list in excel and enter as a hyperlink
    By AlistairM in forum Excel General
    Replies: 0
    Last Post: 01-23-2006, 06:40 AM

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