August 7, 2020

List Files in Folder Create Hyperlink

How to list all files in a folder and create hyperlink for each file using VBA. We have learnt how to loop through files in a folder and sub-folders using the DIR function. Today we learn how to list all files in a folder using the File System Object.

Watch the video below:

List All Files in a Folder & Create Hyperlink for Each File

Here’s the complete VBA macro code to list all files in a folder and then apply an hyperlink to each of the files:

Option Explicit

Sub ListAllFilesInFolderCreateHyperlink()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Long

Set oFSO = CreateObject(“Scripting.Filesystemobject”)
Set oFolder = oFSO.getfolder(“C:\MyHyperlinkedFiles”)

i = 1

For Each oFile In oFolder.Files
Cells(i + 1, 2) = oFile.Name
Cells(i + 1, 3) = oFile.Path
Range(Cells(i + 1, 1), Cells(i + 1, 1)).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=oFile.Path, TextToDisplay:=oFile.Name

i = i + 1

Next oFile

End Sub

List Files in Folder & Create Hyperlink for Each File

Download a sample VBA tutorial file for practice:

3 thoughts on “List Files in Folder Create Hyperlink

  1. Good day. How do I get hold ofDinesh Kumar Takyar. I need to ask him to help me with vba with a scanner

  2. give me your advice

    i need to get some excel file where stored in subfolder

    give me your advice how to get subfolder in vba

Comments are closed.