Not tested, but possibly...
Sub Not_Tested_on_Network()
Dim sSourcePath As String, sDestinationPath As String
Dim sFileType As String, iCol As Long
Dim v As Variant, d As Object, k As Variant, fso As Object
Dim rg As Range, i As Long
sSourcePath = "\\nas01\Archivio Disegni\DV1\" 'CHANGE AS NEEDED
sDestinationPath = "C:\Users\luca\Desktop\DRW\" 'CHANGE AS NEEDED
sFileType = "pdf" 'CHANGE AS NEEDED
'Get column to write to
Select Case sFileType
Case "pdf"
iCol = 2
Case "dfx"
iCol = 3
Case "dwg"
iCol = 4
End Select
'Get all files including sub folders (fullnames)
v = fn_FileList(sSourcePath, sFileType)
'Add fullnames and filenames to dictionary
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = CreateObject("Scripting.Dictionary")
For Each k In v
d.Add fso.getfilename(k), k
Next k
'Get partial filenames to search
Set rg = Sheets("Foglio1").Range(Cells(5, 1), Cells(Rows.Count, 1).End(xlUp))
For i = 1 To rg.Rows.Count
If d.exists(rg.Cells(i, 1) & "." & sFileType) Then
rg.Cells(i, iCol) = sFileType & " exists"
fso.copyfile d(rg.Cells(i, 1) & "." & sFileType), sDestinationPath
Else
rg.Cells(i, iCol) = sFileType & " does not exist"
End If
Next i
End Sub
Function fn_FileList(sPath As String, sFileType As String)
'Gets all filenames from path and sub folders with named extension
fn_FileList = Split(CreateObject("WScript.Shell") _
.exec("%ComSpec% /c dir /a-d /s /b """ & sPath & "*." & sFileType & "*""""") _
.stdout.readall, vbCrLf)
End Function
Bookmarks