Link Listing to Individual Files

RYL

New Member
Joined
Nov 13, 2023
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello I am needing some help. I have a listing of invoice numbers in Excel. For each invoice listed I have a corresponding PDF document that I want linked to the Excel Cell (could have thousands of rows). PDF are saved. Is there an easy way to use VBA code to link cells to PDF? Thank you.

1699922558173.png
1699922558173.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this
VBA Code:
Sub CREATE_hyperlink_FROM_LIST()

    Dim xFSO As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim xFiDialog As FileDialog
    Dim xPath As String
    Dim xFilename As String
    Dim i As Long
    Dim lastRow As Long
    
    Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)

    With xFiDialog
        .InitialFileName = Application.DefaultFilePath & "\" 'change as desired
        .Title = "Select a folder"
        If .Show = 0 Then Exit Sub
    xPath = .SelectedItems(1) & "\"
    End With
    lastRow = Cells(Rows.Count, "A").End(xlUp).row
    
    For i = 2 To lastRow
        xFilename = Dir(xPath & Cells(i, "A").value & "*.pdf", vbNormal)
        If Len(xFilename) > 0 Then
            ActiveSheet.Hyperlinks.Add Cells(i, 1), xPath & xFilename, , , xFilename
      
        End If
    Next i
    
    
End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub CREATE_hyperlink_FROM_LIST()

    Dim xFSO As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim xFiDialog As FileDialog
    Dim xPath As String
    Dim xFilename As String
    Dim i As Long
    Dim lastRow As Long
   
    Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)

    With xFiDialog
        .InitialFileName = Application.DefaultFilePath & "\" 'change as desired
        .Title = "Select a folder"
        If .Show = 0 Then Exit Sub
    xPath = .SelectedItems(1) & "\"
    End With
    lastRow = Cells(Rows.Count, "A").End(xlUp).row
   
    For i = 2 To lastRow
        xFilename = Dir(xPath & Cells(i, "A").value & "*.pdf", vbNormal)
        If Len(xFilename) > 0 Then
            ActiveSheet.Hyperlinks.Add Cells(i, 1), xPath & xFilename, , , xFilename
     
        End If
    Next i
   
   
End Sub
THANK YOU!
 
Upvote 0

Forum statistics

Threads
1,215,215
Messages
6,123,668
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top