I have some code below of hyperlinking a bunch of files under a file folder. What this code does is that it makes me pick the folder I want to hyperlink. How can I give it specific folder to hyperlink for me already without asking me the filepath? I do not want to pick the folder because it can lead to errors if I pick the wrong folder. I already know which folder I will use.
VBA Code:
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 + 12, 1), xFile.Path, , , xFile.Name
Next
End Sub