In vielen Exceldateien suchen
Danke für deine Antwort. Ich weiß nun wenigstens, dass sich
meine Vermutung bestätigt hat. Ich kann nämlich nicht
programmieren, stehe aber vor einem Berg an Excel-Dateien! Es
ist so hoffnungslos.
Hallo Tweety,
nimm eine leere Mappe.
Alt+F11, Einfügen–Modul, Code reinkopieren, Editor schließen.
Im Blatt, Ansicht–Symbolleisten–Formular, Ziehe dir eine Schaltfläche im Blatt auf, weise ihr das Makro „Suche“ zu.
In A2 schreibst du den jeweiligen Pfad, z.B.
C:\Test
Dann auf die Schaltflöche klicken…
Unten in der Statusleiste siehst du den Fortschritt. Es werden nur genaue Entsprechungen gefunden, Durch Suche nach 123 wird 123.456 nicht gefunden, wohl aber durch Suche nach 123.456 und darum ging es ja wohl.
Mappen mit dem Suchwort in einer Tabelle werden aufgelistet in B
Gruß
Reinhard
Option Explicit
Sub Suche()
Dim pstrPath As String, Wort As String, i As Long, Vorh As Boolean
Dim wks As Worksheet, fs As FileSearch, Zei As Long
ThisWorkbook.Sheets(1).Columns(2).ClearContents
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
End With
On Error Resume Next
Wort = Application.Substitute(InputBox("Suchwort"), ".", "")
pstrPath = Range("A2").Value
Set fs = Application.FileSearch
With fs
.LookIn = pstrPath
.Filename = "\*.xls"
.SearchSubFolders = True
.Execute
For i = 1 To .FoundFiles.Count
Vorh = False
Application.StatusBar = i & " / " & .FoundFiles.Count & " " & .FoundFiles(i)
If Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1) ThisWorkbook.Name Then
If UCase(Right(.FoundFiles(i), 4)) = ".XLS" Then
Workbooks.Open Filename:=.FoundFiles(i), updatelinks:=False
For Each wks In ActiveWorkbook.Worksheets
If Application.CountIf(wks.Rows("1:65536"), Wort) \> 0 Then
Vorh = True
Exit For
End If
Next wks
If Vorh Then
Zei = Zei + 1
ThisWorkbook.Sheets(1).Range("B" & Zei) = .FoundFiles(i)
End If
Workbooks(Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1)).Close SaveChanges:=False
End If
End If
Next i
End With
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.StatusBar = ""
End With
End Sub