Hi,
Need help modifying the below code.
1. I would like the script to run automatically when the file is opened.
2. Instead of browsing & selecting the file location, I need it to automatically use file location "Z:\DEPTS\SAP\SupplierRequirements"
3. When file is closed I data should be cleared from sheet
Need help modifying the below code.
1. I would like the script to run automatically when the file is opened.
2. Instead of browsing & selecting the file location, I need it to automatically use file location "Z:\DEPTS\SAP\SupplierRequirements"
3. When file is closed I data should be cleared from sheet
Code:
Option Explicit
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\" '<<< Startup folder to begin searching from
Range("C3").Select ' Where to start the list of names
With Application.FileDialog(msoFileDialogFolderPicker) 'User input for folder to look at
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then ' If there are files in selected folder
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub