Skip to main content

 How to list all filenames in a folder and create hyperlinks for them in Excel?

Author Xiaoyang Last modified

For your daily work, you may need to import multiple filenames from a folder to a worksheet, and create hyperlinks for each files so that open the file quickly and easily. Maybe, you can copy and paste the filenames and create a hyperlink for it one by one manually, but, this will waste much time if there are hundreds files in the folder. Today, I will talk about some quick and interesting methods to deal with this job.

List all filenames in a folder and create hyperlinks with VBA code

List all filenames in a folder and create hyperlinks with Kutools for Excel


List all filenames in a folder and create hyperlinks with VBA code

To list and create hyperlink with files from a folder, the following VBA code can do you a favor.

1. Activate a new worksheet to put the result.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA: List all filenames in a folder and create hyperlinks

Sub Example1()
'Updateby Extendoffice
    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

4. Then press F5 key to run this code, and choose the folder that you want to list the files from the Browse window, see screenshot:

vba code to choose the folder to list the files

5. After specifying the folder, click OK button, and all the files in the specific folder have been listed into active worksheet with hyperlinks, see screenshot:

all the files in the specific folder are listed with hyperlinks2

Note: If there are subfolders in your specific folder, the files in the subfolders will not be listed.


List all filenames in a folder and create hyperlinks with Kutools for Excel

To list all files both in a folder and its subfolders and created hyperlinks for each file, Kutools for Excel’s Filename List may do you a favor. With this feature, all files in folder and subfolders will be listed at once with some attributes, such as file name, file size, created time, containing folder and so on.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Itegarate with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

If you have installed Kutools for Excel, please do with following steps:

1. Click Kutools Plus > Import & Export > Filename List, see screenshot:

click Filename List feature of kutools

specify the options in the dialog box

2. In the Filename List dialog box, please do the following operations:

(1.) Click browse button button to select the folder that you want to list the filenames;

(2.) Check Include files in subdirectories if you want to list filenames within subfolders, check Include hidden files and folders if you want to list the hidden files;

(3.) Specify the file types that you want to find and list under the Files type section;

(4.) Select the file size unit that you want to display;

(5.) Check Create hyperlinks at the left bottom of the dialog box.

Download Kutools for Excel Now !

3. Then click Ok button, and all the files in the folder and subfolders have been listed in a new worksheet with the hyperlinks as you need, see screenshot:

all the files in the folder and subfolders are listed with the hyperlinks

Click to know more details about the Filename List utility…

Download and free trial Kutools for Excel Now !


Demo: List all filenames in a folder and create hyperlinks with Kutools for Excel

 

Related article:

How to list all files in folder and subfolders into a worksheet?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!