Thema Datum  Von Nutzer Rating
Antwort
06.08.2018 14:24:48 Lars
NotSolved
06.08.2018 21:44:03 Gast27383
NotSolved
07.08.2018 07:00:20 Lars
NotSolved
07.08.2018 07:49:50 SJ
NotSolved
07.08.2018 08:10:12 Lars
NotSolved
07.08.2018 09:02:11 SJ
NotSolved
07.08.2018 09:24:03 Lars
NotSolved
Blau Unterprogramm durchsuchen
07.08.2018 09:55:42 Gast42041
NotSolved
07.08.2018 10:21:48 Lars
NotSolved
07.08.2018 13:04:06 Gast17377
NotSolved
07.08.2018 13:11:18 Lars
NotSolved
07.08.2018 16:39:08 Gast8743
NotSolved
07.08.2018 20:18:45 Gast56205
Solved
08.08.2018 07:27:30 Lars
NotSolved
08.08.2018 08:40:18 Lars
NotSolved

Ansicht des Beitrags:
Von:
Gast42041
Datum:
07.08.2018 09:55:42
Views:
607
Rating: Antwort:
  Ja
Thema:
Unterprogramm durchsuchen

Moin!
HIer mal dein Code angepasst. Sollte eigentlich passen. Die Unterordner sollten mit ausgelsen werden un die Suche ist auf Spalte B beschränkt.

Einfach mal testen.

VG

 

Public Sub Suche()
' öffnet Workbooks im "InPath" und sucht nach "xSearch"
' On Error GoTo err
Dim xSearch As String
xSearch = InputBox("Bitte Suchbegriff eingeben")                                         ' Suchstring anpassen
Dim InPath As String
InPath = "H:\Tests"                                                                      ' Pfad anpassen
                                                                                         ' Erweiterung weiter unten anpassen
 
If Right(InPath, 1) <> "\" Then InPath = InPath & "\"
If Dir(InPath, vbDirectory) = "" Then
  MsgBox "Der Ordner " & InPath & " wurde nicht gefunden.", vbCritical
  Exit Sub
End If
 
Dim found As Boolean, zVerz As Long
Dim WS As Worksheet
Dim WB As Workbook
Dim VWS As Worksheet
Set VWS = ThisWorkbook.Worksheets("Verzeichnis")                                         ' Verzeichnis mit gefundenen Aufragsnummern
Dim f As Range, firstAddress As String
Dim FSO As Object, Element As Object, Datei As Variant, Ordner As Variant
Dim UO As Object
Dim Col As New Collection
Dim UOrdner As New Collection
Set FSO = CreateObject("Scripting.Filesystemobject")
 
UOrdner.Add FSO.getfolder(InPath)

Do While UOrdner.Count > 0
    
    Set Ordner = UOrdner(1)
    UOrdner.Remove 1
    
    For Each UO In Ordner.SubFolders
        UOrdner.Add UO
    Next
    
    For Each Datei In Ordner.Files
        Select Case LCase(FSO.GetExtensionName(Datei))
            Case "xls", "xlsx", "xlsm"                                                       ' Erweiterung anpassen
                If Left(Datei.Name, 1) <> "~" Then Col.Add Datei
        End Select
    Next Datei
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual                                            ' automatische Berechnung ausschalten
    Application.EnableEvents = False                                                         ' Events ausschalten
    Application.DisplayAlerts = False                                                        ' Excel-Dialog-Fenster ausschalten
     
     
     
    zVerz = 2
    VWS.Columns("A").ClearContents
    found = False
    For Each Element In Col
        If Element.Name <> ThisWorkbook.Name Then
            Set WB = Workbooks.Open(Filename:=Element, ReadOnly:=True)
            For Each WS In WB.Worksheets
                With WS.Columns("B:B")   'WS.UsedRange
                Set f = .Find(xSearch, LookIn:=xlValues)
                    If Not f Is Nothing Then
                        firstAddress = f.Address
                        Do
                            VWS.Cells(zVerz, 1).Value = " '" & xSearch & "' Datei: " _
                                & Chr(13) & Element & "     'Blatt: " & WS.Name & "      'Zelle: " & f.Address(0, 0)
                            zVerz = zVerz + 1
    '                        MsgBox "'" & xSearch & "' zuerst gefunden in " _
    '                            & Chr(13) & Element & "'" & WS.Name & "'!" & f.Address(0, 0)
    '                        WS.Range(f.Address(0, 0)).Select
    '                        found = True
    '                        Exit For
                            Set f = .FindNext(f)
                        Loop While Not f Is Nothing And f.Address <> firstAddress
                    End If
                End With
                If found = True Then Exit For
            Next WS
            If found = False Then Workbooks(Element.Name).Close savechanges:=False
        End If
        If found = True Then Exit For
    Next Element
    Application.DisplayAlerts = True
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
Loop
Set FSO = Nothing
Exit Sub
 
err:
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Error: " & vbCrLf & "Fehlernummer: " & err.Number & _
            vbCrLf & "Fehlerbeschreibung: " & err.Description, vbOKOnly + vbCritical, "error"
Set FSO = Nothing
 
End Sub

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
06.08.2018 14:24:48 Lars
NotSolved
06.08.2018 21:44:03 Gast27383
NotSolved
07.08.2018 07:00:20 Lars
NotSolved
07.08.2018 07:49:50 SJ
NotSolved
07.08.2018 08:10:12 Lars
NotSolved
07.08.2018 09:02:11 SJ
NotSolved
07.08.2018 09:24:03 Lars
NotSolved
Blau Unterprogramm durchsuchen
07.08.2018 09:55:42 Gast42041
NotSolved
07.08.2018 10:21:48 Lars
NotSolved
07.08.2018 13:04:06 Gast17377
NotSolved
07.08.2018 13:11:18 Lars
NotSolved
07.08.2018 16:39:08 Gast8743
NotSolved
07.08.2018 20:18:45 Gast56205
Solved
08.08.2018 07:27:30 Lars
NotSolved
08.08.2018 08:40:18 Lars
NotSolved