Hey all, new to forum posting but here we go. I would like to be able to extract all file names from a given folder to a spread sheet that would also create hyperlinks to the files extracted. Also if possible when the script is run for a second time, lets say to update that it would only add new files to the spread sheet. I have tried a macro script file that allows you to select files and it extracts the file names but have no idea as to get it to hyperlink said files and not duplicate pre-existing files. I would appreciate any insight.
Here is a copy of the macro I am currently using.
Option Explicit
Private Sub CommandButton1_Click()
Dim rngSave As Range
Dim lngCount As Long
Dim strPathFile As String
Dim strFname As String
Dim intLastDiv As Integer
Dim n As Integer
On Error GoTo ErrHnd
With ActiveSheet
'find the last used cell in column A
Set rngSave = .Range("A65534").End(xlUp)
' Open the file dialog
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Show
'Copy all path/filenames into column A
For lngCount = 1 To .SelectedItems.Count
strPathFile = .SelectedItems(lngCount)
'find last "/" in path/filename
intLastDiv = 0
For n = 1 To Len(strPathFile)
If Mid(strPathFile, n, 1) = "\" Then
intLastDiv = n
End If
Next n
rngSave.Offset(lngCount - 1, 0) = strPathFile
'split filename from path
'save path in column A
rngSave.Offset(lngCount - 1, 0).Value = Left(strPathFile, intLastDiv)
'save filename in column B
rngSave.Offset(lngCount - 1, 1).Value = Right(strPathFile, Len(strPathFile) - intLastDiv)
Next lngCount
End With
'set column widths to fit
.Range("A1:B" & Format(rngSave.Row + lngCount, "##0")).Columns.AutoFit
End With
Exit Sub
'error handler
ErrHnd:
Err.Clear
End Sub
Bookmarks