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:

Published by

Dinesh Kumar Takyar

Welcome to! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: For a structured Excel VBA training course online you can visit:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.