Notifications
Clear all

Macro buscar arquivos no pc

8 Posts
2 Usuários
0 Reactions
1,916 Visualizações
Charlie-81
(@charlie-81)
Posts: 290
Reputable Member
Topic starter
 

Pessoal... preciso de uma macro que faça busca no pc, como se eu estivesse abrindo o explorer para encontrar algum arquivo.

Blue eye | MB Intel Extreme DX58SO | Termaltake 775W | I7 950 LGA 1366 (Overclock 5.3 GZ) | Corsair Vengeance 16 GB | WC Corsair H70 | Aerocool Touch 2000 | Razer Mamba 4G | Som Volcano 50W RMS | Cooler Zalmam | HD 2TB | Radeon HD 8670 | Monitor 32'

 
Postado : 17/09/2012 5:36 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Não entendi, procurar somente arquivos de Excel??

Tente adaptar...

Sub Macro1()
   Dim objFSO, fso
   Set objFSO = CreateObject("Scripting.FileSystemObject")

   Set mainFolder = objFSO.GetFolder("Seu_Diretório")
   For Each sFold In mainFolder.subfolders
      For Each myFile In sFold.Files
         If myFile.Name Like "*xyz*" Then
            myFile.Copy "Destino"
         End If
      Next
   Next
   
   Set objFSO = Nothing
   Set mainFold = Nothing
  
End Sub

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 17/09/2012 5:49 pm
Charlie-81
(@charlie-81)
Posts: 290
Reputable Member
Topic starter
 

não somente excel... Bom, para ser mais direto: Uma macro que abra o explorer para que eu possa navegar entre as pastas do computador.

Blue eye | MB Intel Extreme DX58SO | Termaltake 775W | I7 950 LGA 1366 (Overclock 5.3 GZ) | Corsair Vengeance 16 GB | WC Corsair H70 | Aerocool Touch 2000 | Razer Mamba 4G | Som Volcano 50W RMS | Cooler Zalmam | HD 2TB | Radeon HD 8670 | Monitor 32'

 
Postado : 17/09/2012 5:51 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Tente adaptar.
Fonte: http://www.vbaexpress.com/kb/getarticle.php?kb_id=800

Option Explicit
 
Sub SrchForFiles()
     ' Searches the selected folders and sub folders for files with the specified
     'extension.  .xls, .doc, .ppt, etc.
     'A new worksheet is produced called "File Search Results".  You can click on the link and go directly
     'to the file you need.
    Dim i As Long, z As Long, Rw As Long
    Dim ws As Worksheet
    Dim y As Variant
    Dim fLdr As String, Fil As String, FPath As String
     
    y = Application.InputBox("Por favor entre com a extenção do arquivo", "Info Request")
    If y = False And Not TypeName(y) = "String" Then Exit Sub
    Application.ScreenUpdating = False
     '*******************************************************************
     'fLdr = BrowseForFolderShell
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Show
        fLdr = .SelectedItems(1)
    End With
     '*******************************************************************
    With Application.FileSearch
        .NewSearch
        .LookIn = fLdr
        .SearchSubFolders = True
        .Filename = y
        Set ws = ThisWorkbook.Worksheets.Add(Sheets(1))
        On Error GoTo 1
2:                      ws.Name = "FileSearch Results"
        On Error GoTo 0
        If .Execute() > 0 Then
            For i = 1 To .FoundFiles.Count
                Fil = .FoundFiles(i)
                 'Get file path from file name
                FPath = Left(Fil, Len(Fil) - Len(Split(Fil, "")(UBound(Split(Fil, "")))) - 1)
                If Left$(Fil, 1) = Left$(fLdr, 1) Then
                    If CBool(Len(Dir(Fil))) Then
                        z = z + 1
                        ws.Cells(z + 1, 1).Resize(, 4) = _
                        Array(Dir(Fil), _
                        FileLen(Fil) / 1000, _
                        FileDateTime(Fil), _
                        FPath)
                        ws.Hyperlinks.Add Anchor:=Cells(z + 1, 1), _
                        Address:=.FoundFiles(i)
                    End If
                End If
            Next i
        End If
    End With
     
    ActiveWindow.DisplayHeadings = False
     
    With ws
        Rw = .Cells.Rows.Count
        With .[A1:D1]
            .Value = [{"Full Name","Kilobytes","Last Modified", "Path"}]
            .Font.Underline = xlUnderlineStyleSingle
            .EntireColumn.AutoFit
            .HorizontalAlignment = xlCenter
        End With
        .[E1:IV1 ].EntireColumn.Hidden = True
        On Error Resume Next
        Range(Cells(Rw, "A").End(3)(2), Cells(Rw, "A")).EntireRow.Hidden = True
        Range(.[A2 ], Cells(Rw, "C")).Sort [A2 ], xlAscending, Header:=xlNo
    End With
     
    Application.ScreenUpdating = True
    Exit Sub
1:          Application.DisplayAlerts = False
    Worksheets("FileSearch Results").Delete
    Application.DisplayAlerts = True
    GoTo 2
End Sub
 

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 17/09/2012 6:18 pm
Charlie-81
(@charlie-81)
Posts: 290
Reputable Member
Topic starter
 

Vou lhe agradecer pela resposta, mas ainda não é o que quero. Acho que deve existir algum comando que ao executar a macro ela abra o explorer.

Blue eye | MB Intel Extreme DX58SO | Termaltake 775W | I7 950 LGA 1366 (Overclock 5.3 GZ) | Corsair Vengeance 16 GB | WC Corsair H70 | Aerocool Touch 2000 | Razer Mamba 4G | Som Volcano 50W RMS | Cooler Zalmam | HD 2TB | Radeon HD 8670 | Monitor 32'

 
Postado : 17/09/2012 6:31 pm
Charlie-81
(@charlie-81)
Posts: 290
Reputable Member
Topic starter
 

encontrei... vou fechar o tópico

Blue eye | MB Intel Extreme DX58SO | Termaltake 775W | I7 950 LGA 1366 (Overclock 5.3 GZ) | Corsair Vengeance 16 GB | WC Corsair H70 | Aerocool Touch 2000 | Razer Mamba 4G | Som Volcano 50W RMS | Cooler Zalmam | HD 2TB | Radeon HD 8670 | Monitor 32'

 
Postado : 17/09/2012 6:52 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Charlie-81

manda aí... quero ver.

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 17/09/2012 6:54 pm
Charlie-81
(@charlie-81)
Posts: 290
Reputable Member
Topic starter
 

opa... em um módulo coloque:

Sub Abrir_Explorer()
    Dim Charlie81_File As String
    Charlie81_File = Application.GetOpenFilename( _
    "Charlie81 - Buscar (*.*), *.*", _
    , "Suporte: valdiney-duarte@hotmail.com", _
    , _
    True)
    Exit Sub
End Sub

Depois é só atribuir à algum botão...

Blue eye | MB Intel Extreme DX58SO | Termaltake 775W | I7 950 LGA 1366 (Overclock 5.3 GZ) | Corsair Vengeance 16 GB | WC Corsair H70 | Aerocool Touch 2000 | Razer Mamba 4G | Som Volcano 50W RMS | Cooler Zalmam | HD 2TB | Radeon HD 8670 | Monitor 32'

 
Postado : 17/09/2012 7:00 pm