+ Reply to Thread
Results 1 to 20 of 20

Auto link from excel to folder's files

Hybrid View

sherif114 Auto link from excel to... 10-29-2020, 09:26 AM
AC PORTA VIA Re: Auto link from excel to... 10-29-2020, 06:29 PM
sherif114 Re: Auto link from excel to... 10-29-2020, 06:48 PM
AC PORTA VIA Re: Auto link from excel to... 10-29-2020, 07:37 PM
sherif114 Re: Auto link from excel to... 10-29-2020, 08:25 PM
AC PORTA VIA Re: Auto link from excel to... 10-29-2020, 08:30 PM
sherif114 Re: Auto link from excel to... 10-30-2020, 02:11 AM
AC PORTA VIA Re: Auto link from excel to... 10-30-2020, 05:51 PM
sherif114 Re: Auto link from excel to... 10-31-2020, 02:11 AM
AC PORTA VIA Re: Auto link from excel to... 10-31-2020, 11:01 AM
sherif114 Re: Auto link from excel to... 10-31-2020, 01:11 PM
sherif114 Re: Auto link from excel to... 11-03-2020, 01:24 AM
AC PORTA VIA Re: Auto link from excel to... 11-03-2020, 11:42 AM
sherif114 Re: Auto link from excel to... 11-03-2020, 11:05 PM
AC PORTA VIA Re: Auto link from excel to... 11-04-2020, 09:25 AM
sherif114 Re: Auto link from excel to... 11-04-2020, 10:47 PM
AC PORTA VIA Re: Auto link from excel to... 11-05-2020, 09:23 AM
AC PORTA VIA Re: Auto link from excel to... 11-05-2020, 01:37 PM
sherif114 Re: Auto link from excel to... 11-06-2020, 12:22 AM
AC PORTA VIA Re: Auto link from excel to... 11-06-2020, 09:46 AM
  1. #1
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Auto link from excel to folder's files

    Dear all
    i am seeking some help regarding
    how to generate link automatically in excel to files in a specific folder once you add the file to the folder or even when i click a button to check the new files in the folder
    Last edited by AliGW; 10-31-2020 at 11:25 AM. Reason: Redacted for legibility.

  2. #2
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Sub Example1()
        Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xFiDialog As FileDialog
        Dim xPath As String
        Dim I As Integer
        Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
        If xFiDialog.Show = -1 Then
            xPath = xFiDialog.SelectedItems(1)
        End If
        Set xFiDialog = Nothing
        If xPath = "" Then Exit Sub
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            I = I + 1
            ActiveSheet.Hyperlinks.Add Cells(I, 1), xFile.Path, , , xFile.Name
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    thank you so much
    is there any way to make it insert the folder too?

    and my main question is are there any way to add the file to the sheet automatically without running the macro, and it happened once I open the file that contains the macro ??
    (make the macro work automatically by opening the file and go to a specific folder determined in it and list all folders in columns with their files )

    again THANK YOU SO MUCH , IT IS REALLY HELPFULL CODE
    Last edited by AliGW; 10-31-2020 at 11:26 AM. Reason: Redacted for legibility.

  4. #4
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    add below to ThisWorkbook module- excel file needs to be saved as Macro-Enabled Worksheet (.xlsm)

    Private Sub Workbook_Open()
      Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xPath As String
        Dim I As Integer
    'change file path on below line to correct Folder path
         xPath = "C:\Users\xxxx\Desktop\New folder"
    
        If xPath = "" Then Exit Sub
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            I = I + 1
            ActiveSheet.Hyperlinks.Add Cells(I, 1), xFile.Path, , , xFile.Name
        Next
    End Sub

  5. #5
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    yes it works, thank you so much,,

    is there any way to catch the folder names too?

  6. #6
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Yes but I don’t have access to my pc right now
    Will do it tomorrow

  7. #7
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    thank you so much

  8. #8
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Try this
    Private Sub Workbook_Open()
        Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xPath As String
        Dim i As Long
          For Each Sheet In ThisWorkbook.Worksheets
            If Sheet.Name = "Files" Then
                Sheets("Files").Cells.Delete
                f = True
                Exit For
            Else
                f = False
            End If
        Next
        If Not f Then Sheets.Add.Name = "Files"
        Sheets("Files").Select
       
        xPath = "C:\Users\xxxx\Desktop\New folder"
     
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            i = i + 1
            ActiveSheet.Hyperlinks.Add Cells(i, 1), xFile.Path, , , xFile.Name
        Next
          
            With CreateObject("scripting.filesystemobject")
            For Each xFolder In .GetFolder(xPath).SubFolders
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(i + 2, 1), _
                     Address:=xPath & Application.PathSeparator & xFolder.Name, _
                     TextToDisplay:=xFolder.Name
              i = i + 1
        Next
    
        End With
    End Sub

  9. #9
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    thank you,, very good it works perfectly
    is there any way to make any different sign like( font color, bold font ) for the folder names?

  10. #10
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    right now folder path is separated from the rest with empty row but yes you can have that too
    Private Sub Workbook_Open()
        Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xPath As String
        Dim i As Long
          For Each Sheet In ThisWorkbook.Worksheets
            If Sheet.Name = "Files" Then
                Sheets("Files").Cells.Delete
                f = True
                Exit For
            Else
                f = False
            End If
        Next
        If Not f Then Sheets.Add.Name = "Files"
        Sheets("Files").Select
       
        xPath = "C:\Users\xxxx\Desktop\New folder"
     
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            i = i + 1
            ActiveSheet.Hyperlinks.Add Cells(i, 1), xFile.Path, , , xFile.Name
        Next
          
            With CreateObject("scripting.filesystemobject")
            For Each xFolder In .GetFolder(xPath).SubFolders
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(i + 2, 1), _
                     Address:=xPath & Application.PathSeparator & xFolder.Name, _
                     TextToDisplay:=xFolder.Name
                     Cells(i + 2, 1).Font.Bold = True
                     Cells(i + 2, 1).Interior.ColorIndex = 8
              i = i + 1
        Next
    
        End With
    End Sub

  11. #11
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    amazing as usual

  12. #12
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    Dear AC PORTA VIA
    can add the "modified date" of the files in another column beside the column of the names of the files??
    this will help to sort the file according to modified date.
    kind regards,,

  13. #13
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Try this
    Private Sub Workbook_Open()
    Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xPath As String
        Dim i As Long
       
          For Each Sheet In ThisWorkbook.Worksheets
            If Sheet.Name = "Files" Then
                Sheets("Files").Cells.Delete
                f = True
                Exit For
            Else
                f = False
            End If
        Next
        
        If Not f Then Sheets.Add.Name = "Files"
        Sheets("Files").Select
    
          xPath = "C:\Users\xxxx\Desktop\New folder"
    
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            i = i + 1
            ActiveSheet.Hyperlinks.Add Cells(i + 1, 1), xFile.Path, , , xFile.Name
            ActiveSheet.Cells(i + 1, 2).Value = xFile.DateLastModified
            ActiveSheet.Cells(i + 1, 3).Value = xFile.DateCreated
            ActiveSheet.Cells(i + 1, 4).Value = xFile.DateLastAccessed
        Next
            With CreateObject("scripting.filesystemobject")
            For Each xFolder In .GetFolder(xPath).SubFolders
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(i + 3, 1), _
                     Address:=xPath & Application.PathSeparator & xFolder.Name, _
                     TextToDisplay:=xFolder.Name
                        Cells(i + 3, 1).Font.Bold = True
                        Cells(i + 3, 1).Interior.ColorIndex = 8
            ActiveSheet.Cells(i + 3, 2).Value = xFolder.DateLastModified
            ActiveSheet.Cells(i + 3, 3).Value = xFolder.DateCreated
            ActiveSheet.Cells(i + 3, 4).Value = xFolder.DateLastAccessed
            
            i = i + 1
      
        Next
        End With
    
    Range("A1").FormulaR1C1 = "Name"
        Range("B1").FormulaR1C1 = "DateLastModified"
        Range("C1").FormulaR1C1 = "DateCreated"
        Range("D1").FormulaR1C1 = "DateLastAccessed"
        Columns("A:D").EntireColumn.AutoFit
    End Sub
    Last edited by AC PORTA VIA; 11-03-2020 at 09:49 PM.

  14. #14
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    Dear AC PORTA VIA
    IT WORKS , but for sorry it lists the modified date in another sheet, not in the same sheet

    regards,,

  15. #15
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    It creates new sheet named “ Files” to prevent overwriting anything in active sheet
    Everything you need should be on the same sheet-
    Name DateLastModified DateCreated DateLastAccessed

  16. #16
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    thanks ,,
    what i got is file names in a sheet and all other dates in another sheet, so does at what macro do?

  17. #17
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Macro runs fine when I ran it
    All info with file name hyperlink and modified date are on the same sheet named Files
    There is something in your workbook that switch between sheet name Files and some other sheet in the middle of running macro
    Do you have any other macro in your workbook?

  18. #18
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    Use macro below - just remainder anything in active sheet in the first 4 columns ( A-D) will be deleted before new data is added
    Private Sub Workbook_Open()
    Dim xFSO As Object
        Dim xFolder As Object
        Dim xFile As Object
        Dim xPath As String
        Dim i As Long
    
    ActiveSheet.Range(Cells(1, 1), Cells(Rows.Count, 4)).ClearContents
    ActiveSheet.Range(Cells(1, 1), Cells(Rows.Count, 4)).ClearFormats
    
          xPath = "C:\Users\xxxx\Desktop\New folder"
    
        Set xFSO = CreateObject("Scripting.FileSystemObject")
        Set xFolder = xFSO.GetFolder(xPath)
        For Each xFile In xFolder.Files
            i = i + 1
    
            ActiveSheet.Hyperlinks.Add Cells(i + 1, 1), xFile.Path, , , xFile.Name
            ActiveSheet.Cells(i + 1, 2).Value = xFile.DateLastModified
            ActiveSheet.Cells(i + 1, 3).Value = xFile.DateCreated
            ActiveSheet.Cells(i + 1, 4).Value = xFile.DateLastAccessed
        Next
    
            With CreateObject("scripting.filesystemobject")
            For Each xFolder In .GetFolder(xPath).SubFolders
            ActiveSheet.Hyperlinks.Add Anchor:=Cells(i + 3, 1), _
                     Address:=xPath & Application.PathSeparator & xFolder.Name, _
                     TextToDisplay:=xFolder.Name
                        Cells(i + 3, 1).Font.Bold = True
                        Cells(i + 3, 1).Interior.ColorIndex = 8
            ActiveSheet.Cells(i + 3, 2).Value = xFolder.DateLastModified
            ActiveSheet.Cells(i + 3, 3).Value = xFolder.DateCreated
            ActiveSheet.Cells(i + 3, 4).Value = xFolder.DateLastAccessed
    
            i = i + 1
    
        Next
        End With
    
    Range("A1").FormulaR1C1 = "Name"
        Range("B1").FormulaR1C1 = "DateLastModified"
       Range("C1").FormulaR1C1 = "DateCreated"
        Range("D1").FormulaR1C1 = "DateLastAccessed"
        Columns("A:D").EntireColumn.AutoFit
    End Sub
    Last edited by AC PORTA VIA; 11-06-2020 at 09:45 AM.

  19. #19
    Registered User
    Join Date
    09-30-2017
    Location
    egypt
    MS-Off Ver
    2010
    Posts
    16

    Re: Auto link from excel to folder's files

    perfect as usual, but there are extra "xPath" in the code, but when I remove it, it works fantastic
    I really appreciated it

  20. #20
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Auto link from excel to folder's files

    You are welcome
    Glad it works for you

+ 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. Replies: 1
    Last Post: 05-17-2018, 01:47 PM
  2. Replies: 3
    Last Post: 01-29-2018, 11:34 AM
  3. VBA to Auto Zip the Folder or Files
    By mvinay in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-28-2014, 05:20 AM
  4. Replies: 1
    Last Post: 09-22-2010, 11:00 AM
  5. Create automatic link to files in same folder.
    By Little Master in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-26-2009, 11:45 AM
  6. auto open excel files in the folder
    By ccs1981 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2009, 02:19 AM
  7. auto open the excel files in the folder
    By ccs1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2008, 04:16 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