Thema Datum  Von Nutzer Rating
Antwort
05.01.2016 07:03:28 Andre
NotSolved
06.01.2016 15:27:50 Gast28524
NotSolved
06.01.2016 15:40:24 Andre
NotSolved
06.01.2016 16:20:53 Gast25935
NotSolved
07.01.2016 07:56:43 Andre
NotSolved
06.01.2016 22:17:39 Gast69812
NotSolved
07.01.2016 05:51:07 Gast10186
NotSolved
07.01.2016 07:45:58 Andre
NotSolved
07.01.2016 08:06:27 Andre
NotSolved
09.01.2016 19:10:40 Gast62795
NotSolved
11.01.2016 08:20:07 Andre
NotSolved
11.01.2016 10:22:55 Gast7783
NotSolved
11.01.2016 12:36:32 Andre
NotSolved
11.01.2016 12:39:35 Andre
NotSolved
11.01.2016 15:56:45 Gast87431
NotSolved
11.01.2016 16:14:03 Andre
NotSolved
11.01.2016 16:30:15 Gast67223
NotSolved
12.01.2016 08:21:54 Gast77619
NotSolved
11.01.2016 16:34:42 Gast89738
NotSolved
12.01.2016 08:27:34 Andre
NotSolved
12.01.2016 12:41:22 Gast14356
NotSolved
12.01.2016 14:12:59 Andre
NotSolved
12.01.2016 14:17:04 Andre
NotSolved
12.01.2016 15:46:33 Gast57141
NotSolved
13.01.2016 07:56:18 Andre
NotSolved
13.01.2016 08:09:51 Andre
NotSolved
13.01.2016 08:32:16 Gast86894
NotSolved
13.01.2016 08:42:11 Andre
NotSolved
13.01.2016 19:20:12 Gast86704
NotSolved
14.01.2016 08:32:14 Andre
NotSolved
14.01.2016 10:10:53 Gast34177
NotSolved
14.01.2016 10:28:38 Andre
NotSolved
14.01.2016 10:45:46 Gast25298
NotSolved
14.01.2016 10:58:07 Andre
NotSolved
14.01.2016 11:33:50 Gast21502
NotSolved
14.01.2016 12:18:11 Andre
NotSolved
14.01.2016 15:49:42 Gast23760
NotSolved
14.01.2016 16:09:09 Andre
****
NotSolved
14.01.2016 18:55:41 Gast81853
NotSolved
15.01.2016 08:18:04 Andre
NotSolved
15.01.2016 19:30:59 Gast45694
NotSolved
18.01.2016 08:09:01 Andre
NotSolved
18.01.2016 08:12:08 Andre
NotSolved
18.01.2016 18:02:48 Gast82440
NotSolved
19.01.2016 08:40:26 Andre
NotSolved
19.01.2016 13:36:07 Gast75130
NotSolved
19.01.2016 14:04:24 Andre
NotSolved
19.01.2016 18:19:20 Gast65228
NotSolved
19.01.2016 18:20:55 Gast29977
NotSolved
20.01.2016 07:21:35 Andre
NotSolved
20.01.2016 11:42:16 aufran
NotSolved
20.01.2016 11:54:57 Andre
NotSolved
20.01.2016 12:03:47 Gast44577
NotSolved
20.01.2016 15:58:00 aufran
NotSolved
21.01.2016 21:41:23 aufran
NotSolved
21.01.2016 21:52:00 Gast14641
NotSolved
20.01.2016 12:01:05 Gast18965
NotSolved
20.01.2016 12:07:06 Gast343
NotSolved
20.01.2016 12:18:06 Andre
NotSolved
20.01.2016 12:28:46 Gast95544
Solved
20.01.2016 20:02:43 Gast15375
NotSolved
21.01.2016 07:52:14 Andre
NotSolved
21.01.2016 10:46:39 Gast54269
NotSolved
21.01.2016 10:59:39 Gast19460
NotSolved
21.01.2016 15:04:13 Andre
NotSolved
21.01.2016 15:09:07 Andre
NotSolved
21.01.2016 15:55:44 Gast30371
NotSolved
25.01.2016 07:53:22 Andre
NotSolved
25.01.2016 08:35:01 Andre
NotSolved
25.01.2016 08:35:07 Andre
NotSolved
22.01.2016 13:51:05 Gast11423
NotSolved
Blau No Problem
22.01.2016 22:45:16 aufran
NotSolved
25.01.2016 08:08:43 Andre
NotSolved
25.01.2016 11:18:33 aufran
NotSolved
25.01.2016 12:07:03 Andre
NotSolved
25.01.2016 08:06:16 Andre
NotSolved
25.01.2016 19:38:52 Gast92881
NotSolved
25.01.2016 19:40:23 Gast31903
NotSolved
26.01.2016 07:26:40 Andre
NotSolved
26.01.2016 09:25:34 Gast31028
NotSolved
26.01.2016 10:15:47 Andre
NotSolved
26.01.2016 11:48:57 Gast10723
NotSolved
26.01.2016 13:23:31 Andre
NotSolved
27.01.2016 14:23:48 Gast20611
NotSolved
27.01.2016 14:48:05 Andre
NotSolved
27.01.2016 14:56:24 Andre
NotSolved
27.01.2016 15:30:27 Gast76603
NotSolved
27.01.2016 15:30:28 Gast42470
NotSolved
27.01.2016 15:57:14 Andre
NotSolved
27.01.2016 16:21:33 Andre
NotSolved
27.01.2016 20:54:35 Gast808
NotSolved
28.01.2016 07:25:57 Andre
NotSolved
28.01.2016 16:20:47 Gast66068
Solved
29.01.2016 12:28:40 Andre
NotSolved
29.01.2016 17:35:37 Gast3880
NotSolved
30.01.2016 10:06:13 aufran
NotSolved

Ansicht des Beitrags:
Von:
aufran
Datum:
22.01.2016 22:45:16
Views:
745
Rating: Antwort:
  Ja
Thema:
No Problem

Guten Abend,

NUN - nicht ganz so. Ablaufschema in meinen Codes kurz gefasst:

Ab Startpunkt (Const m_Path) nach unten und jede Abzweigung bis zum Ende.

1) Hier nur eine Liste der Ordner die den (Const m_IncludeFolder) genügen.

Nach dieser Liste in den aufgeführten Ordnern die Datei-Typprüfung und

wenn Typ =  OK, dann Vergleich mit der Dateinamenvorgabe (Const m_IncludeFiles)

Vergleich erfolgreich, dann nur diesen Pfad die schon leere Liste zurück.

2) Die Liste erneut abarbeiten, dort stehen nun ja nur die Workbook-FullName der Gesuchten.

Und erst jetzt erfolgt gezielt der Dateizugriff (Open bzw. OLEDB)

3) Der Rest ist ja bekannt

Casus Cnaxus ist Pkt. 1) - wie viele "dumme" Unterordner liegen unter dem Startpunkt,

denn womöglich steht dort ein Ordner "Woswasi"  und enthält die gesuchten Unterordner!

Ergo kommt das FSO ins Schwitzen, wenn sich ein paar Hundert Ordner unter der Startwurzel

eingereiht haben. Die Zeit kann nicht beeinflusst werden - das FSO Objekt ist immer unsortiert!

 

Die Bremse Workbook.Open hatten wir ja schon und ohne diese Methode benötigt der Rest

d.h. Pkt2) u. Pkt 3) nur wenige Einhundertstel Sekunden.

 

EGAL, dein Wunsch ist der Vater des Gedankens und überhaupt nicht schwer:

Aus dem QUEUE mach ich STACK und schon wird so aufgelegt, dass das unterste Verzeichnis

in jedem Ast zu Oberst liegt. Dann nehme ich eben nur 1 Blatt vom Stapel und verwerfe den Rest.

 

Option Explicit
' ***********************************************************************************
' ***** ACHTUNG - Microsoft Scripting Runtime in VBA-Editor-Verweise anhaken *******
' ***********************************************************************************
'
'ab hier
Const m_Path As String = "V:\0101\SCHULEN"                                   'Startup
'
'Liste der Ordner wo
Const m_IncludeFolder As String = "SCHULEN,Rahmenvertrag, Abrechnung"
'Const m_IncludeFolder As String = ""                                'all Folders
'
'Liste der Dateien wo, gesucht wird immer UCASE()
Const m_IncludeFiles As String = "_Planung, Testfile"                'File includes
'
'Voreinstellung was
Const m_DATA As Variant = "aktuell"                                  'search DATA
'
' ----------------------------------------------------------------------------------
'NUR EXCEL Dateien
Const m_FileType As String = "Microsoft Excel"                        'only
' ----------------------------------------------------------------------------------
'
'Auswahl wie abgefragt wird
' ***********************************************************************************
' ***** ACHTUNG - TURBO = "Microsoft.ACE.OLEDB.12.0"
' ***********************************************************************************
Const m_Turbo As Boolean = True
'Const m_Turbo As Boolean = False ' = Workbook.Open
'
' ***********************************************************************************
' ***** ACHTUNG - keine Fehlersteuerung - d.h. sinnlose Konstanten vermeiden!  *****
' ***********************************************************************************
'
'
'
Dim objFso As Object                                              'FileSystemObject
Dim oStack As Object                                              'Stack
Dim objSortedList As Object                                       'Sorted List
Dim IsLimited As Boolean                                          'Folders restricted
Dim ArrLimited() As String                                        'Array restricted
Dim strDATA As String
'
Sub DoItStackLast()
If Len(m_IncludeFiles) = 0 Then Exit Sub                          'useless
If m_FileType <> "Microsoft Excel" Then Exit Sub                  'useless
'
strDATA = InputBox("gesuchter Wert = ", , m_DATA)
If strDATA = "" Then Exit Sub                                     'useless
'
Set oStack = CreateObject("System.Collections.Stack")
   If Len(m_IncludeFolder) > 0 Then
      ArrLimited = Split(m_IncludeFolder, ",")
      IsLimited = True
   End If
   Call FolderTest
   Debug.Print Join(oStack.toarray, Chr(10))
   If oStack.Count > 0 Then Call FilesTest
   Debug.Print Join(oStack.toarray, Chr(10))
   If oStack.Count > 0 Then
      If m_Turbo = True Then                                      'OLEDB catch
         Call HitOLEDB
      Else                                                        'OPEN File
         Call HitOpen
      End If
   End If
   '
   Call MsgBox("Fertig", vbExclamation, "")
   '
Set oStack = Nothing
End Sub
'
Private Sub HitOLEDB()
Dim strPath As String
Dim blnHit As Boolean, lngCnt As Long
'
Application.ScreenUpdating = False
   Sheets(1).Columns(1).ClearHyperlinks
   Sheets(1).Columns(1).ClearContents
   Do While oStack.Count > 0
      blnHit = False
      strPath = oStack.Pop
      Debug.Print "Hit ", strPath
      '
      blnHit = FindItOnce(strPath, strDATA)
      '
      If blnHit = True Then
         lngCnt = lngCnt + 1
         Cells(lngCnt, 1).Hyperlinks.Add anchor:=Cells(lngCnt, 1), Address:=strPath
      End If
   Loop
Application.ScreenUpdating = True
End Sub
'
Private Sub HitOpen()
Dim strPath As String
Dim oWs As Excel.Worksheet, Rng As Excel.Range, hRng As Excel.Range
Dim blnHit As Boolean, lngCnt As Long
'
Application.ScreenUpdating = False
   Sheets(1).Columns(1).ClearHyperlinks
   Sheets(1).Columns(1).ClearContents
   Do While oStack.Count > 0
      blnHit = False
      strPath = oStack.Pop
      Debug.Print "Hit ", strPath
      Workbooks.Open (strPath)
         For Each oWs In Workbooks(2).Sheets
            Set Rng = oWs.UsedRange
             Set hRng = Rng.Find(strDATA)
             If Not hRng Is Nothing Then blnHit = True
         Next oWs
      Workbooks(2).Close False
      If blnHit = True Then
         lngCnt = lngCnt + 1
         Cells(lngCnt, 1).Hyperlinks.Add anchor:=Cells(lngCnt, 1), Address:=strPath
      End If
   Loop
Application.ScreenUpdating = True
End Sub
'
Private Sub FilesTest()
Dim fldStart As Object                                            'Folder
Dim fld As Object                                                 'Folder
Dim fl As Object                                                  'File
Dim strPath As String, strFull As String, lngCnt As Long
'
Set objFso = CreateObject("scripting.FileSystemObject")
Set objSortedList = CreateObject("System.Collections.Sortedlist")
'
   Do While oStack.Count > 0
      strPath = oStack.Pop
      Set fldStart = objFso.getfolder(strPath)
      Set fld = fldStart.Files
      For Each fl In fld '.Files
         If InStr(fl.Name, Chr(126)) = 0 Then                     'temp. files
         'Debug.Print fl.Name, fl.Type
            If InStr(fl.Type, m_FileType) > 0 Then
               strFull = fl
               '***************************************************************
               If HitFile(fl.Name) = True Then
                  objSortedList.Add strFull, 0                    'first hit
                  Exit For
               '***************************************************************
               End If
            End If
         End If
      Next fl
   Loop
'
   oStack.Clear
   For lngCnt = 0 To objSortedList.Count - 1
      oStack.Push objSortedList.GetKey(lngCnt)
   Next lngCnt
'
'
Set objFso = Nothing
Set fld = Nothing
Set fl = Nothing
Set objSortedList = Nothing
End Sub
'
Private Sub FolderTest()
Dim fldStart As Object                                            'Folder
Dim fld As Object                                                 'Folder
Dim str As String, lngCnt As Long
'
Set objFso = CreateObject("scripting.FileSystemObject")
Set fldStart = objFso.getfolder(m_Path)
Set objSortedList = CreateObject("System.Collections.Sortedlist")
'
   For Each fld In fldStart.subFolders
      str = fld
      Debug.Print str
      If IsLimited Then
         If HitLimit(str) Then _
            objSortedList.Add str, 0
      Else
            objSortedList.Add str, 0
      End If
      Call sbFolderTest(fld)
   Next fld
'
   For lngCnt = 0 To objSortedList.Count - 1
      oStack.Push objSortedList.GetKey(lngCnt)
   Next lngCnt
'
Set objFso = Nothing
Set fldStart = Nothing
Set objSortedList = Nothing
End Sub
'
Private Function sbFolderTest(sFolder As Object)
Dim sbfld As Object
Dim sbStr As String
   For Each sbfld In sFolder.subFolders
      sbStr = sbfld
      If IsLimited Then
         If HitLimit(sbStr) Then _
         objSortedList.Add sbStr, 0
      Else
         objSortedList.Add sbStr, 0
      End If
      Call sbFolderTest(sbfld)
   Next sbfld
End Function
'
Private Function HitLimit(ByVal strHit As String) As Boolean
Dim varE As Variant
   For Each varE In ArrLimited
      If InStr(strHit, Trim(varE)) > 0 Then HitLimit = True
   Next varE
End Function
'
Function HitFile(ByVal strHit As String) As Boolean
Dim Arr() As String, ustrHit As String, varE As Variant
   ustrHit = UCase(strHit)
   Arr = Split(m_IncludeFiles, ",")
   For Each varE In Arr
      If InStr(ustrHit, UCase(Trim(varE))) > 0 Then HitFile = True
   Next varE
End Function
'
Private Function FindItOnce(ByVal strFullName As String, Optional ByVal ToDo As Variant) As Boolean
'
'**********************************************************************************
' ACHTUNG TURBO
'**********************************************************************************
' ggf. können Einschränkungen am installierten Office den  OLEDB-Zugriff verhindern
' - hier getestet unter Excel Version 15.0 = Excel 2013
' - Verweise im VBA Editor beachten
' ggf. AccessDatabaseEngine passend zum Windows Betreibmichsystem
' http://www.microsoft.com/de-de/download/details.aspx?id=13255
'**********************************************************************************
'
Const SEL_FROM As String = "SELECT * FROM "
'
Dim oConn As Object
Dim oTblRs As Object, oRs As Object, oFld As Object
Dim sSQL As String
Dim strFnd As String
Dim oList As Object                                               'ArrayList
'
On Error GoTo nix
         Set oList = CreateObject("System.Collections.ArrayList")
'
         Set oConn = CreateObject("ADODB.Connection")
         Set oTblRs = CreateObject("ADODB.Recordset")
         With oConn
            .Provider = "Microsoft.ACE.OLEDB.12.0"
            .ConnectionString = "Data Source=" & strFullName & ";" & _
            "Extended Properties=""Excel 12.0 Xml;HDR=NO;IMEX=1"""
            .Open
         End With
         'tables
         Set oTblRs = oConn.OpenSchema(20)
         '
         If Not oTblRs.EOF Then
            sSQL = SEL_FROM & Chr(91) & oTblRs.Fields(2).Value & Chr(93)
            Set oRs = CreateObject("ADODB.Recordset")
            oRs.Open sSQL, oConn, 3, 1, 1
            If Not oRs.EOF Then
               For Each oFld In oRs.Fields
                  oRs.MoveFirst
                  strFnd = oFld.Name & " = " & Chr(39) & ToDo & Chr(39)
                  oRs.Find strFnd
                  If oRs.EOF = False Then oList.Add strFullName
               Next oFld
               
            End If
         End If
         '
         If oList.Count > 0 Then FindItOnce = True
'
nix:
Set oConn = Nothing
Set oTblRs = Nothing
Set oList = Nothing
End Function

 


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
05.01.2016 07:03:28 Andre
NotSolved
06.01.2016 15:27:50 Gast28524
NotSolved
06.01.2016 15:40:24 Andre
NotSolved
06.01.2016 16:20:53 Gast25935
NotSolved
07.01.2016 07:56:43 Andre
NotSolved
06.01.2016 22:17:39 Gast69812
NotSolved
07.01.2016 05:51:07 Gast10186
NotSolved
07.01.2016 07:45:58 Andre
NotSolved
07.01.2016 08:06:27 Andre
NotSolved
09.01.2016 19:10:40 Gast62795
NotSolved
11.01.2016 08:20:07 Andre
NotSolved
11.01.2016 10:22:55 Gast7783
NotSolved
11.01.2016 12:36:32 Andre
NotSolved
11.01.2016 12:39:35 Andre
NotSolved
11.01.2016 15:56:45 Gast87431
NotSolved
11.01.2016 16:14:03 Andre
NotSolved
11.01.2016 16:30:15 Gast67223
NotSolved
12.01.2016 08:21:54 Gast77619
NotSolved
11.01.2016 16:34:42 Gast89738
NotSolved
12.01.2016 08:27:34 Andre
NotSolved
12.01.2016 12:41:22 Gast14356
NotSolved
12.01.2016 14:12:59 Andre
NotSolved
12.01.2016 14:17:04 Andre
NotSolved
12.01.2016 15:46:33 Gast57141
NotSolved
13.01.2016 07:56:18 Andre
NotSolved
13.01.2016 08:09:51 Andre
NotSolved
13.01.2016 08:32:16 Gast86894
NotSolved
13.01.2016 08:42:11 Andre
NotSolved
13.01.2016 19:20:12 Gast86704
NotSolved
14.01.2016 08:32:14 Andre
NotSolved
14.01.2016 10:10:53 Gast34177
NotSolved
14.01.2016 10:28:38 Andre
NotSolved
14.01.2016 10:45:46 Gast25298
NotSolved
14.01.2016 10:58:07 Andre
NotSolved
14.01.2016 11:33:50 Gast21502
NotSolved
14.01.2016 12:18:11 Andre
NotSolved
14.01.2016 15:49:42 Gast23760
NotSolved
14.01.2016 16:09:09 Andre
****
NotSolved
14.01.2016 18:55:41 Gast81853
NotSolved
15.01.2016 08:18:04 Andre
NotSolved
15.01.2016 19:30:59 Gast45694
NotSolved
18.01.2016 08:09:01 Andre
NotSolved
18.01.2016 08:12:08 Andre
NotSolved
18.01.2016 18:02:48 Gast82440
NotSolved
19.01.2016 08:40:26 Andre
NotSolved
19.01.2016 13:36:07 Gast75130
NotSolved
19.01.2016 14:04:24 Andre
NotSolved
19.01.2016 18:19:20 Gast65228
NotSolved
19.01.2016 18:20:55 Gast29977
NotSolved
20.01.2016 07:21:35 Andre
NotSolved
20.01.2016 11:42:16 aufran
NotSolved
20.01.2016 11:54:57 Andre
NotSolved
20.01.2016 12:03:47 Gast44577
NotSolved
20.01.2016 15:58:00 aufran
NotSolved
21.01.2016 21:41:23 aufran
NotSolved
21.01.2016 21:52:00 Gast14641
NotSolved
20.01.2016 12:01:05 Gast18965
NotSolved
20.01.2016 12:07:06 Gast343
NotSolved
20.01.2016 12:18:06 Andre
NotSolved
20.01.2016 12:28:46 Gast95544
Solved
20.01.2016 20:02:43 Gast15375
NotSolved
21.01.2016 07:52:14 Andre
NotSolved
21.01.2016 10:46:39 Gast54269
NotSolved
21.01.2016 10:59:39 Gast19460
NotSolved
21.01.2016 15:04:13 Andre
NotSolved
21.01.2016 15:09:07 Andre
NotSolved
21.01.2016 15:55:44 Gast30371
NotSolved
25.01.2016 07:53:22 Andre
NotSolved
25.01.2016 08:35:01 Andre
NotSolved
25.01.2016 08:35:07 Andre
NotSolved
22.01.2016 13:51:05 Gast11423
NotSolved
Blau No Problem
22.01.2016 22:45:16 aufran
NotSolved
25.01.2016 08:08:43 Andre
NotSolved
25.01.2016 11:18:33 aufran
NotSolved
25.01.2016 12:07:03 Andre
NotSolved
25.01.2016 08:06:16 Andre
NotSolved
25.01.2016 19:38:52 Gast92881
NotSolved
25.01.2016 19:40:23 Gast31903
NotSolved
26.01.2016 07:26:40 Andre
NotSolved
26.01.2016 09:25:34 Gast31028
NotSolved
26.01.2016 10:15:47 Andre
NotSolved
26.01.2016 11:48:57 Gast10723
NotSolved
26.01.2016 13:23:31 Andre
NotSolved
27.01.2016 14:23:48 Gast20611
NotSolved
27.01.2016 14:48:05 Andre
NotSolved
27.01.2016 14:56:24 Andre
NotSolved
27.01.2016 15:30:27 Gast76603
NotSolved
27.01.2016 15:30:28 Gast42470
NotSolved
27.01.2016 15:57:14 Andre
NotSolved
27.01.2016 16:21:33 Andre
NotSolved
27.01.2016 20:54:35 Gast808
NotSolved
28.01.2016 07:25:57 Andre
NotSolved
28.01.2016 16:20:47 Gast66068
Solved
29.01.2016 12:28:40 Andre
NotSolved
29.01.2016 17:35:37 Gast3880
NotSolved
30.01.2016 10:06:13 aufran
NotSolved