Public FolderPath As String
Sub GetFileNamesWithHyperlinks()
Dim FileName As String
Dim i As Integer
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select a Folder"
.AllowMultiSelect = False
If .Show = True Then
FolderPath = .SelectedItems(1)
End If
End With
Range("A2:B" & Range("B" & Rows.Count).End(xlUp).Row).ClearContents
FileName = Dir(FolderPath & "\*.*")
i = 4
Do While FileName <> ""
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 2), Address:=FolderPath & "\" & FileName, TextToDisplay:=FileName
i = i + 1
FileName = Dir()
Loop
Range("B2").Value = "File Names with Hyperlinks from A Specific Folder"
End Sub
Sub UpdateNewFiles()
Dim lastRow As Long
lastRow = Range("B" & Rows.Count).End(xlUp).Row
Dim existingFiles() As Variant
existingFiles = Range("B2:B" & lastRow).Value
Dim FileName As String
FileName = Dir(FolderPath & "\*.*")
Dim i As Long
i = lastRow + 1
Do While FileName <> ""
Dim found As Boolean
found = False
For j = 1 To UBound(existingFiles, 1)
If existingFiles(j, 1) = FileName Then
found = True
Exit For
End If
Next j
If Not found Then
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 2), Address:=FolderPath & "\" & FileName, TextToDisplay:=FileName
i = i + 1
End If
FileName = Dir()
Loop
End Sub