Hello,
I have a folder that has sub-folders. Under each sub folder, there are Excel files. Each week, the file path for folders and Excel files under these folders change.
My objective is to loop through these sub-folders and create a shortcut of each Excel file in the main folder.
Each Single time, I am trying to prompt users to select a specific main-folder as it changes from week to week.
This is a code I edited and tried to use but it is not working:
I would really appreciate your help,
Thank you,
I have a folder that has sub-folders. Under each sub folder, there are Excel files. Each week, the file path for folders and Excel files under these folders change.
My objective is to loop through these sub-folders and create a shortcut of each Excel file in the main folder.
Each Single time, I am trying to prompt users to select a specific main-folder as it changes from week to week.
This is a code I edited and tried to use but it is not working:
VBA Code:
Sub CreateFileShortcut()
Dim FileSystem As Object
Dim HostFolder As String
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
HostFolder = myPath
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub DoFolder(Folder)
Dim SubFolder
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
Dim File
For Each File In Folder.Files
' Operate on each file
sShortcutLocation = File.Name & ".lnk"
With CreateObject("WScript.Shell").CreateShortcut(sShortcutLocation)
.TargetPath = File.Path
.Description = "Shortcut to the file"
.Save
End With
Next
End Sub
I would really appreciate your help,
Thank you,