Notifications
Clear all

Procura arquivos em uma pasta e retorna o nome dos arquivos

2 Posts
2 Usuários
0 Reactions
850 Visualizações
(@lucianojr)
Posts: 0
New Member
Topic starter
 

Boa noite,

Preciso de uma macro que procure arquivos em uma pasta e me retorne em uma célula qualquer o nome dos arquivos encontrados.

Exemplo.

Procurar por Luciano*.txt na pasta C:Funcionários

Resultado na célula A1= LucianoSilva.txt, A2=LucianoSouza.txt, A3=LucianoQQCOISA.txt...

Alguém pode me ajudar?

Obrigado

 
Postado : 07/05/2014 3:50 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 


Veja se ajuda:


Sub BuscarArquivos()

pasta = "C:Funcionários"

arq = InputBox("Digitar palavra chave")
ext = InputBox("Digitar extensão do arquivo")

lin = 1

Dim fs, f, f1, fc, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(pasta)
Set fc = f.Files
For Each f1 In fc
On Error Resume Next
If Application.WorksheetFunction.Search(arq, f1, 1) > 0 And Right(f1, 3) = ext Then
x = Err.Number
If Err.Number = 0 Then
Cells(lin, 1) = Mid(f1, Len(pasta) + 1, 50)
lin = lin + 1
Err.Number = 0
End If
End If
Next

End Sub

 
Postado : 07/05/2014 4:47 pm