Hello to all.
The macro attached to search the files in the folder.
it is possible that the macro looks for even in sub-folders?
'Option Explicit
Public ApplicationFileSearch As New FileSearch
Sub apri_e_verifica()
Dim obiettivo
Dim A As Range
Dim trova As FileSearch
Dim cartella As Integer
Dim x As Long
Dim cl As Range
Dim nome_file As String
Dim vuoto As Boolean
Set trova = ApplicationFileSearch
vuoto = False
'IMPOSTO LA VARIABILE "x" COME INDICE DI RICERCA DELL'ULTIMA RIGA
'OCCUPATA DELLA COLONNA A DEL FILE "search_file"
x = Workbooks("search_file.xls").Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row + 1
'CANCELLO IL RANGE DOVE VERRANNO INSERITI I DATI
Workbooks("search_file.xls").Sheets(1).Range("A2:C" & x).ClearContents
obiettivo = InputBox("Inserisci il codice da cercare", "Ricerca codice")
Application.ScreenUpdating = False
'SE L'INPUTBOX è VUOTA, AVVISA ED ESCE DALLA ROUTINE
If obiettivo = "" Then
vuoto = True
MsgBox "devi inserire un codice", vbExclamation, "ATTENZIONE"
End If
If Not vuoto Then
With trova
'INDICO IL PERCORSO DELLA CARTELLA DOVE SONO I FILE DA APRIRE
.LookIn = "C:\Users\massimo\Desktop\MAX\moduli_salvati"
'INDICO IL TIPO DI FILE DA APRIRE
.FileName = "*.xls"
'METODO EXECUTE RESTITUISCE IL NUMERO DEI FILES DELLA
'DIRECTORY SPECIFICATA; SE è = 0 AVVISA ED ESCE DALLA ROUTINE
If .Execute() > 0 Then
'CICLO FOR CHE APRE TUTTI I FILE CONTENUTI NELLA CARTELLA "moduli_salvati"
'CON LA PROPRIETà "FoundFiles"
'DALL'HELP ON LINE :
'Restituisce un oggetto FoundFiles contenente i nomi di tutti i
'file trovati durante la ricerca. Di sola lettura.
' E CON LA PROPRIETà "Count" CHE RESTITUISCE IL NUMERO
'DELL'ULTIMO FILE
For cartella = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(cartella)
nome_file = ActiveWorkbook.Name
Set A = Workbooks(nome_file).Sheets(1).Range("L7:L31")
'CICLO PER VERIFICARE L'ESISTENZA DEL CODICE NEI FILES; SE LO TROVA,
'INSERISCE IL CODICE, IL NOME DEL FILE E L'INDIRIZZO DELLA CELLA
'NEL FILE "search_file", ED ESSENDO UN CODICE UNIVOCO, ESCE DAL CICLO E
'PASSA AL FILE SUCCESSIVO
For Each cl In A
If cl = obiettivo Then
With Workbooks("search_file.xls").Sheets(1)
'RE-IMPOSTO LA VARIABILE "x" COME INDICE DI RICERCA DELL'ULTIMA RIGA
'OCCUPATA DELLA COLONNA A DEL FILE "search_file"
x = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Range("A" & x) = cl
.Range("B" & x) = Workbooks(nome_file).Name
.Range("C" & x) = cl.Address(False, False)
End With
Exit For
End If
Next cl
'CHIUDO LA CARTELLA ATTIVA
Workbooks(nome_file).Close
'PROSSIMO FILE DA APRIRE
Next cartella
Else
MsgBox "Nella directory scelta non ci sono Files"
End If
End With
If Workbooks("search_file.xls").Sheets(1).Range("A2") = "" Then
MsgBox "Non è stato trovato nessun codice " & obiettivo, vbExclamation, _
"VERIFICA CONCLUSA"
Else
MsgBox "Il codice " & obiettivo & " è stato trovato in " & x - 1 & " file/s", _
vbInformation, "VERIFICA CONCLUSA"
End If
End If
Application.ScreenUpdating = True
Set A = Nothing
Set trova = Nothing
End Sub
thanks in advance.
max_max
Bookmarks