Hi,
I have an Excel file where users select the most recent version of a file in a network folder and import it. I would like to automate this step so that the macro automatically imports the most recent file.
I have tried to incorporate the code from this answer but cannot figure out the syntax as I am using SetUNCPath.
https://www.mrexcel.com/forum/excel...b-open-most-recently-created-file-folder.html
Does anyone know how I could do this?
Thanks
I have an Excel file where users select the most recent version of a file in a network folder and import it. I would like to automate this step so that the macro automatically imports the most recent file.
I have tried to incorporate the code from this answer but cannot figure out the syntax as I am using SetUNCPath.
https://www.mrexcel.com/forum/excel...b-open-most-recently-created-file-folder.html
Does anyone know how I could do this?
Code:
Sub CommandButton1_Click()
Dim wb As Workbook, wb2 As Workbook
Dim sPath As String
'Set source workbook
Set wb = ActiveWorkbook
sPath = "\\Network Path\Sub Folder"
If SetUNCPath(sPath) <> 0 Then
FileToOpen = Application.GetOpenFilename _
("CSV Files,*.csv", _
1, "Select One File To Open", , False)
''
If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "No File Specified"
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen
End If
Else
MsgBox "Error in setting the UNC path - " & sPath
End If
Thanks