Hallo mal wieder.
(diemal hab ich im I-Net schon nach ner Lösung gesucht - aber nichts gefunden )
Folgendes - habe ein Suchenformular -->
Option Explicit
Dim fso As New FileSystemObject
Dim fld As Folder
Private Sub Commandbutton1\_Click()
Dim nDirs As Long, nFiles As Long, lSize As Currency
Dim sDir As String, sSrchString As String
ListBox1.Clear
sDir = "c:\test\"
sSrchString = TextBox1
'MousePointer = vbHourglass
Label1.Caption = "Searching " & vbCrLf & UCase(sDir) & "..."
lSize = FindFile(sDir, sSrchString, nDirs, nFiles)
'MousePointer = vbDefault
MsgBox Str(nFiles) & " " & " Dateien mit dem Namen " & sSrchString & " gefunden in" & Str(nDirs) & \_
" Verzeichnis", vbInformation
'MsgBox "Total Size = " & lSize & " bytes"
End Sub
Private Function FindFile(ByVal sFol As String, sFile As String, \_
nDirs As Long, nFiles As Long) As Currency
Dim tFld As Folder, tFil As File, FileName As String
On Error GoTo Catch
Set fld = fso.GetFolder(sFol)
FileName = dir(fso.BuildPath(fld.path, sFile), vbNormal Or \_
vbHidden Or vbSystem Or vbReadOnly)
While Len(FileName) 0
FindFile = FindFile + FileLen(fso.BuildPath(fld.path, \_
FileName))
nFiles = nFiles + 1
ListBox1.AddItem fso.BuildPath(fld.path, dir) ' Load ListBox
FileName = dir() ' Get next file
DoEvents
Wend
Label1 = "Searching " & vbCrLf & fld.path & "..."
nDirs = nDirs + 1
If fld.SubFolders.Count \> 0 Then
For Each tFld In fld.SubFolders
DoEvents
FindFile = FindFile + FindFile(tFld.path, sFile, nDirs, nFiles)
Next
End If
Exit Function
Catch: FileName = ""
Resume Next
End Function
Private Sub ListBox1\_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim dir As String
dir = ListBox1
Shell "explorer.exe " & dir, vbNormalFocus
End Sub
Wenn ich das aufrufe funktioniert es wunderbar.
Wenn ich die Form und den Code aber in ein vorhandenes Projekt importiere dann sucht er nicht. Es kommt keine Fehlermeldung - es kommt nur das 0 Dateien gefunden wurden, ohne das es aber sucht.
Ich kann dem ganzen ned wirklich folgen warum er hier rumzickt…
Hat zufällig jemand von euch ne Idee?
Gruß Rolf