Anzeige
Archiv - Navigation
1692to1696
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Suche Zeile für Zeile

Suche Zeile für Zeile
12.05.2019 13:53:41
MaBlu
Hallo
ich habe ein Problem, das ich hier schon mal angefragt habe aber keine Antwort bekam, eventuell habe ich etwas kompliziert gefragt, darum versuch ichs nochmal.
Ich habe ein gutes Makro das in bestimmten Dateien nach Namen sucht in der Tabelle (H:H) hat er ein Datum und name gefunden listet Excel die Datei nicht auf, das möchte ich änderm so dass wenn in einer Zeile H:H kein Datum steht beim Namen soll die Datei aufgelistet werden!
hier das Makro:
Public Sub searchHyperlink()
Dim objFileSearch As clsFileSearch
Dim objWB As Workbook, objSh As Worksheet, objThisSH As Worksheet, objFind As Range
Dim lngIndex As Long, lngRow As Long
Dim strPath As String, strName As String
On Error GoTo ErrorHandler
With Application
.ScreenUpdating = False
.EnableEvents = False
.AskToUpdateLinks = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
strName = InputBox("Bitte gesuchten Namen eingeben!", "Hyperlinkliste", "?")
If strName  CStr(False) And (Len(strName)) Then
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "T:\05_UP\80_Kunden\Neu\Kunden\"  'Startverzeichnis
.Title = "Hyperlink erstellen - Ordnerwahl"
.ButtonName = "Start..."
.InitialView = msoFileDialogViewList
If .Show = -1 Then
strPath = .SelectedItems(1)
If Right(strPath, 1)  "\" Then strPath = strPath & "\"
End If
End With
If Len(strPath) Then
ActiveSheet.Unprotect Password:="dobro"
Set objThisSH = ThisWorkbook.Sheets("Hyperlink") 'Ausgabeblatt in dieser Datei
objThisSH.Range("A2:A" & Rows.Count).ClearContents
objThisSH.Range("A1") = "Dateien unerledigt für '" & strName & "'"
lngRow = 2
Set objFileSearch = New clsFileSearch
With objFileSearch
.NewSearch = True
.CaseSenstiv = False
.Extension = "*.xls*"
.FolderPath = strPath
.SearchLike = "*APQP*.xls*"
.SubFolders = True
If .Execute(Sort_by_Date_Create, Sort_Order_Descending) > 0 Then
For lngIndex = 1 To .FileCount
'Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName)
Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName, ReadOnly:=True)
For Each objSh In objWB.Worksheets
If objSh.Name Like "CL-Phase*" Then
Set objFind = objSh.Range("H:H").Find(What:=strName, Lookat:=xlWhole, _' hier  _
sollte Zeile für Zeile abgeklärt werden?
LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
If Not objFind Is Nothing Then
If objFind.Offset(0, 4) = "" Or Not IsDate(objFind.Offset(0, 4)) Then
objThisSH.Hyperlinks.Add Anchor:=objThisSH.Cells(lngRow, 1), _
Address:=objWB.FullName, TextToDisplay:=objWB.FullName
objThisSH.Cells(lngRow, 1).Style = "Hyperlink"
lngRow = lngRow + 1
Exit For
End If
End If
End If
Next
objWB.Close False
Next
End If
End With
End If
ActiveSheet.Protect Password:="dobro"
End If
ErrorHandler:
With Application
.ScreenUpdating = True
.EnableEvents = True
.AskToUpdateLinks = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
Set objFileSearch = Nothing
Set objThisSH = Nothing
Set objWB = Nothing
Set objSh = Nothing
Set objFind = Nothing
End Sub
Hier die Datei mit der Gesucht wird.
https://www.herber.de/bbs/user/129722.zip
und hier die datei die gesucht wird
https://www.herber.de/bbs/user/129723.zip
besten Dank für eure hilfe gruss MaBlu

11
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 14:53:27
Nepumuk
Hallo MaBlu,
teste mal:
Public Sub searchHyperlink()
    Dim objFileSearch As clsFileSearch
    Dim objWB As Workbook, objSh As Worksheet, objThisSH As Worksheet, objFind As Range
    Dim lngIndex As Long, lngRow As Long
    Dim strPath As String, strName As String, strFirstAddress As String
    
    On Error GoTo ErrorHandler
    
    strName = InputBox("Bitte gesuchten Namen eingeben!", "Hyperlinkliste", "?")
    
    If strName <> CStr(False) And (Len(strName)) Then
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .AskToUpdateLinks = False
            .DisplayAlerts = False
            .Calculation = xlCalculationManual
        End With
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = "T:\05_UP\80_Kunden\Neu\Kunden\" 'Startverzeichnis
            .Title = "Hyperlink erstellen - Ordnerwahl"
            .ButtonName = "Start..."
            .InitialView = msoFileDialogViewList
            If .Show = -1 Then
                strPath = .SelectedItems(1) & "\"
            End If
        End With
        
        If Len(strPath) Then
            Set objThisSH = ThisWorkbook.Sheets("Hyperlink") 'Ausgabeblatt in dieser Datei
            With objThisSH
                .Unprotect Password:="dobro"
                .Range("A2:A" & Rows.Count).ClearContents
                .Range("A1") = "Dateien unerledigt für '" & strName & "'"
            End With
            lngRow = 2
            Set objFileSearch = New clsFileSearch
            
            With objFileSearch
                .NewSearch = True
                .CaseSenstiv = False
                .Extension = "*.xls*"
                .FolderPath = strPath
                .SearchLike = "*APQP*.xls*"
                .SubFolders = True
                If .Execute(Sort_by_Date_Create, Sort_Order_Descending) > 0 Then
                    For lngIndex = 1 To .FileCount
                        Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName, ReadOnly:=True)
                        For Each objSh In objWB.Worksheets
                            If objSh.Name Like "CL-Phase*" Then
                                Set objFind = objSh.Range("H:H").Find(What:=strName, Lookat:=xlWhole, _
                                    LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
                                If Not objFind Is Nothing Then
                                    strFirstAddress = objFind.Address
                                    Do
                                        If Not IsDate(objFind.Offset(0, 4).Value) Then
                                            objThisSH.Hyperlinks.Add Anchor:=objThisSH.Cells(lngRow, 1), _
                                                Address:=objWB.FullName, TextToDisplay:=objWB.FullName
                                            objThisSH.Cells(lngRow, 1).Style = "Hyperlink"
                                            lngRow = lngRow + 1
                                        End If
                                        Set objFind = objSh.Range("H:H").FindNext(After:=objFind)
                                    Loop Until objFind.Address = strFirstAddress
                                End If
                            End If
                        Next
                        objWB.Close False
                    Next
                End If
            End With
        End If
        objSh.Protect Password:="dobro"
    End If
    
    ErrorHandler:
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .AskToUpdateLinks = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
    End With
    
    Set objFileSearch = Nothing
    Set objThisSH = Nothing
    Set objWB = Nothing
    Set objSh = Nothing
    Set objFind = Nothing
End Sub

Gruß
Nepumuk
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 18:10:20
MaBlu
Hallo Nepumuk
Funktioniert soweit super, die Ausgabe wird jetzt soviel mal verlinkt wie es gefunden wird, könnte man das noch so einstellen dass der Link trotzdem nur einmal erscheint?
und eine zweite Bitte kann man noch eine Prüfung einbauen dass das Makro nur mit der Suche beginnt wenn im Blatt "Projekt- und QM-Plan" in der Zelle "I4" ein Datum steht!
Das wäre der Hammer, aber zuerst schon mal vielen Dank für die Hilfe.
Gruss MaBlu
AW: Suche Zeile für Zeile
12.05.2019 18:34:00
Nepumuk
Hallo MaBlu,
teste mal:
Public Sub searchHyperlink()
    Dim objFileSearch As clsFileSearch
    Dim objWB As Workbook, objSh As Worksheet, objThisSH As Worksheet, objFind As Range
    Dim lngIndex As Long, lngRow As Long
    Dim strPath As String, strName As String, strFirstAddress As String
    
    On Error GoTo ErrorHandler
    
    strName = InputBox("Bitte gesuchten Namen eingeben!", "Hyperlinkliste", "?")
    
    If strName <> CStr(False) And (Len(strName)) Then
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .AskToUpdateLinks = False
            .DisplayAlerts = False
            .Calculation = xlCalculationManual
        End With
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = "T:\05_UP\80_Kunden\Neu\Kunden\" 'Startverzeichnis
            .Title = "Hyperlink erstellen - Ordnerwahl"
            .ButtonName = "Start..."
            .InitialView = msoFileDialogViewList
            If .Show = -1 Then
                strPath = .SelectedItems(1) & "\"
            End If
        End With
        
        If Len(strPath) Then
            Set objThisSH = ThisWorkbook.Sheets("Hyperlink") 'Ausgabeblatt in dieser Datei
            With objThisSH
                .Unprotect Password:="dobro"
                .Range("A2:A" & Rows.Count).ClearContents
                .Range("A1") = "Dateien unerledigt für '" & strName & "'"
            End With
            lngRow = 2
            Set objFileSearch = New clsFileSearch
            
            With objFileSearch
                .NewSearch = True
                .CaseSenstiv = False
                .Extension = "*.xls*"
                .FolderPath = strPath
                .SearchLike = "*APQP*.xls*"
                .SubFolders = True
                If .Execute(Sort_by_Date_Create, Sort_Order_Descending) > 0 Then
                    For lngIndex = 1 To .FileCount
                        Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName, ReadOnly:=True)
                        If ProjectStart(objWB) Then
                            For Each objSh In objWB.Worksheets
                                If objSh.Name Like "CL-Phase*" Then
                                    Set objFind = objSh.Range("H:H").Find(What:=strName, Lookat:=xlWhole, _
                                        LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
                                    If Not objFind Is Nothing Then
                                        strFirstAddress = objFind.Address
                                        Do
                                            If Not IsDate(objFind.Offset(0, 4).Value) Then
                                                objThisSH.Hyperlinks.Add Anchor:=objThisSH.Cells(lngRow, 1), _
                                                    Address:=objWB.FullName, TextToDisplay:=objWB.FullName
                                                objThisSH.Cells(lngRow, 1).Style = "Hyperlink"
                                                lngRow = lngRow + 1
                                                Exit For
                                            End If
                                            Set objFind = objSh.Range("H:H").FindNext(After:=objFind)
                                        Loop Until objFind.Address = strFirstAddress
                                    End If
                                End If
                            Next
                        End If
                        objWB.Close False
                    Next
                End If
            End With
        End If
        objSh.Protect Password:="dobro"
    End If
    
    ErrorHandler:
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .AskToUpdateLinks = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
    End With
    
    Set objFileSearch = Nothing
    Set objThisSH = Nothing
    Set objWB = Nothing
    Set objSh = Nothing
    Set objFind = Nothing
End Sub

Private Function ProjectStart(ByRef probjWorkbook As Workbook) As Boolean
    Dim objWorksheet As Worksheet
    For Each objWorksheet In probjWorkbook.Worksheets
        If objWorksheet.Name = "Projekt- und QM-Plan" Then
            If IsDate(objWorksheet.Cells(4, 9).Value) Then
                ProjectStart = True
                Exit For
            End If
        End If
    Next
    Set objWorksheet = Nothing
End Function

Gruß
Nepumuk
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 18:41:21
MaBlu
Hallo Nepumik
leider nein jetzt findet er gar nichts mehr, oder er verlinkt es auf jedenfalls nicht mehr?
Gruss MaBlu
AW: Suche Zeile für Zeile
12.05.2019 18:48:57
Nepumuk
Hallo MaBlu,
versteh ich nicht, denn deine Testmappe wurde verlinkt. Ich habe darin nach dem Namen "L. Russo" gesucht.
Gruß
Nepumuk
AW: Suche Zeile für Zeile
12.05.2019 19:06:13
Nepumuk
Hallo MaBlu,
kommentiere mal die On Error - Anweisung aus. Du bekommst nämlich gar nicht mit wenn ein Fehler auftritt.
Besser noch, lass dir Fehler anzeigen:
Public Sub searchHyperlink()
    Dim objFileSearch As clsFileSearch
    Dim objWB As Workbook, objSh As Worksheet, objThisSH As Worksheet, objFind As Range
    Dim lngIndex As Long, lngRow As Long
    Dim strPath As String, strName As String, strFirstAddress As String
    
    On Error GoTo err_exit
    
    strName = InputBox("Bitte gesuchten Namen eingeben!", "Hyperlinkliste", "?")
    
    If strName <> CStr(False) And (Len(strName)) Then
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .AskToUpdateLinks = False
            .DisplayAlerts = False
            .Calculation = xlCalculationManual
        End With
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = "T:\05_UP\80_Kunden\Neu\Kunden\" 'Startverzeichnis
            .Title = "Hyperlink erstellen - Ordnerwahl"
            .ButtonName = "Start..."
            .InitialView = msoFileDialogViewList
            If .Show = -1 Then
                strPath = .SelectedItems(1) & "\"
            End If
        End With
        
        If Len(strPath) Then
            Set objThisSH = ThisWorkbook.Sheets("Hyperlink") 'Ausgabeblatt in dieser Datei
            With objThisSH
                .Unprotect Password:="dobro"
                .Range("A2:A" & Rows.Count).ClearContents
                .Range("A1") = "Dateien unerledigt für '" & strName & "'"
            End With
            lngRow = 2
            Set objFileSearch = New clsFileSearch
            
            With objFileSearch
                .NewSearch = True
                .CaseSenstiv = False
                .Extension = "*.xls*"
                .FolderPath = strPath
                .SearchLike = "*APQP*.xls*"
                .SubFolders = True
                If .Execute(Sort_by_Date_Create, Sort_Order_Descending) > 0 Then
                    For lngIndex = 1 To .FileCount
                        Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName, ReadOnly:=True)
                        If ProjectStart(objWB) Then
                            For Each objSh In objWB.Worksheets
                                If objSh.Name Like "CL-Phase*" Then
                                    Set objFind = objSh.Range("H:H").Find(What:=strName, Lookat:=xlWhole, _
                                        LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
                                    If Not objFind Is Nothing Then
                                        strFirstAddress = objFind.Address
                                        Do
                                            If Not IsDate(objFind.Offset(0, 4).Value) Then
                                                objThisSH.Hyperlinks.Add Anchor:=objThisSH.Cells(lngRow, 1), _
                                                    Address:=objWB.FullName, TextToDisplay:=objWB.FullName
                                                objThisSH.Cells(lngRow, 1).Style = "Hyperlink"
                                                lngRow = lngRow + 1
                                                Exit For
                                            End If
                                            Set objFind = objSh.Range("H:H").FindNext(After:=objFind)
                                        Loop Until objFind.Address = strFirstAddress
                                    End If
                                End If
                            Next
                        End If
                        objWB.Close False
                    Next
                End If
            End With
        End If
        objSh.Protect Password:="dobro"
    End If
    
    sub_exit:
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .AskToUpdateLinks = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
    End With
    
    Set objFileSearch = Nothing
    Set objThisSH = Nothing
    Set objWB = Nothing
    Set objSh = Nothing
    Set objFind = Nothing
    
    Exit Sub
    
    err_exit:
    
    Call MsgBox("Fehler " & CStr(Err.Number) & vbLf & vbLf & _
        Err.Description, vbCritical, "Programmfehler")
    Resume sub_exit
    
End Sub

Gruß
Nepumuk
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 19:38:52
MaBlu
Hallo Nepomuk
du hattest recht, der Fehler entstand weil ich die Datei offen hatte sah ich als ich dei Fehlermeldung sehen konnte!
Gibt es auch eine Möglichkeit dass das Makro das prüft wenn eine Datei offen ist (Schreibgeschützt öffnen), das Problem habe ich so wieso auf dem Server, wenn einer die Datei bereits bearbeitet.
Das mit der Fehlerroutine war der entschiedene Fehler danke für deine Bemühungen!
Wenn ich alle Dateien geschlossen habe funktioniert es prächtig.
Gruss MaBlu
AW: Suche Zeile für Zeile
12.05.2019 20:06:49
Nepumuk
Hallo MaBlu,
teste mal:
Public Sub searchHyperlink()
    Dim objFileSearch As clsFileSearch
    Dim objWB As Workbook, objSh As Worksheet, objThisSH As Worksheet, objFind As Range
    Dim lngIndex As Long, lngRow As Long
    Dim strPath As String, strName As String, strFirstAddress As String
    
    On Error GoTo err_exit
    
    strName = InputBox("Bitte gesuchten Namen eingeben!", "Hyperlinkliste", "?")
    
    If strName <> CStr(False) And (Len(strName)) Then
        
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            .AskToUpdateLinks = False
            .DisplayAlerts = False
            .Calculation = xlCalculationManual
        End With
        
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = "T:\05_UP\80_Kunden\Neu\Kunden\" 'Startverzeichnis
            .Title = "Hyperlink erstellen - Ordnerwahl"
            .ButtonName = "Start..."
            .InitialView = msoFileDialogViewList
            If .Show = -1 Then
                strPath = .SelectedItems(1) & "\"
            End If
        End With
        
        If Len(strPath) Then
            Set objThisSH = ThisWorkbook.Sheets("Hyperlink") 'Ausgabeblatt in dieser Datei
            With objThisSH
                .Unprotect Password:="dobro"
                .Range("A2:A" & Rows.Count).ClearContents
                .Range("A1") = "Dateien unerledigt für '" & strName & "'"
            End With
            lngRow = 2
            Set objFileSearch = New clsFileSearch
            
            With objFileSearch
                .NewSearch = True
                .CaseSenstiv = False
                .Extension = "*.xls*"
                .FolderPath = strPath
                .SearchLike = "*APQP*.xls*"
                .SubFolders = True
                If .Execute(Sort_by_Date_Create, Sort_Order_Descending) > 0 Then
                    For lngIndex = 1 To .FileCount
                        If Left$(.Files(lngIndex).FI_FileName, 2) <> "~$" Then
                            Set objWB = Workbooks.Open(.Files(lngIndex).FI_FullName, ReadOnly:=True)
                            If ProjectStart(objWB) Then
                                For Each objSh In objWB.Worksheets
                                    If objSh.Name Like "CL-Phase*" Then
                                        Set objFind = objSh.Range("H:H").Find(What:=strName, Lookat:=xlWhole, _
                                            LookIn:=xlValues, MatchCase:=False, SearchFormat:=False)
                                        If Not objFind Is Nothing Then
                                            strFirstAddress = objFind.Address
                                            Do
                                                If Not IsDate(objFind.Offset(0, 4).Value) Then
                                                    objThisSH.Hyperlinks.Add Anchor:=objThisSH.Cells(lngRow, 1), _
                                                        Address:=objWB.FullName, TextToDisplay:=objWB.FullName
                                                    objThisSH.Cells(lngRow, 1).Style = "Hyperlink"
                                                    lngRow = lngRow + 1
                                                    Exit For
                                                End If
                                                Set objFind = objSh.Range("H:H").FindNext(After:=objFind)
                                            Loop Until objFind.Address = strFirstAddress
                                        End If
                                    End If
                                Next
                            End If
                            objWB.Close False
                        End If
                    Next
                End If
            End With
        End If
        objThisSH.Protect Password:="dobro"
    End If
    
    sub_exit:
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .AskToUpdateLinks = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
    End With
    
    Set objFileSearch = Nothing
    Set objThisSH = Nothing
    Set objWB = Nothing
    Set objSh = Nothing
    Set objFind = Nothing
    
    Exit Sub
    
    err_exit:
    
    Call MsgBox("Fehler " & CStr(Err.Number) & vbLf & vbLf & _
        Err.Description, vbCritical, "Programmfehler")
    Resume sub_exit
    
End Sub

Gruß
Nepumuk
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 20:18:30
MaBlu
Hallo Nepumuk
ja das ist toll geht super auch wenn die Datei geöffnet ist super das wollte ich schon lange haben sehr sehr gut!
Jetzt wäre nur noch das mit dem Datum auf der Ersten Seite in den gesuchten Dateien
"Projekt- und QM-Plan" in der Zelle "I4" wenn da kein Datum steht soll die Datei nicht geprüft werden, dann ist das Projekt noch nicht gestartet.
Hast du für das Problem auch noch eine so Geniale Idee?
Für deine Bemühungen bedanke ich mich schon jetzt du hast miir schon sehr weit geholfen viele Dank.
Gruss MaBLu
AW: Suche Zeile für Zeile
12.05.2019 20:45:09
Nepumuk
Hallo MaBlu,
das macht die Funktion "ProjectStart". Die funktionier, das habe ich getestet.
Gruß
Nepumuk
Anzeige
AW: Suche Zeile für Zeile
12.05.2019 21:05:56
MaBlu
Hallo Nepumuk
es Funktioniert und ich merk's nicht mal Sorry. Aber ich kann's Makro halt noch nicht Lesen.
Ich bedanke mich bei dir für die sehr schnelle und Professionelle Hilfe, ich denke da hab ich wieder viel gelernt, wenn ich's auch noch nicht ganz umsetzen kann aber Schritt für Schritt hoffe ich auch hinter das Makro Geheimnis zu kommen!
Du hast mir wircklich sehr geholfen viele vielen Dank für deine Hilfe.
Ich wünsche dir eine tolle Woche und verbleibe mit vielen Grüssen MaBlu

111 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige