Option Explicit
Private Sub ListBox1Laden()
Dim strPath$, strFile$, i&, Thema As Variant, arr()
Erase arr
If strPath = "" Then strPath = ShellVerzeichnisBrowser
If strPath <> "" Then
strPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
strFile = Dir(strPath & "*.jpg", vbNormal)
Do While strFile <> ""
i = i + 1
ReDim Preserve arr(1 To 2, 1 To i)
arr(1, i) = strPath
arr(2, i) = strFile
strFile = Dir
Loop
End If
If strPath <> "" Then
Tabelle1.Cells(1, 1).Resize(UBound(arr, 2), 2) = Application.Transpose(arr)
End If
End Sub
Private Function ShellVerzeichnisBrowser(Optional ByVal defaultPath = "") As String
Dim objItem As Object, objShell As Object, objFolder As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0&, "Bitte Verzeichnis anklicken", 0&, defaultPath)
If objFolder Is Nothing Then GoTo weiter
Set objItem = objFolder.Self
ShellVerzeichnisBrowser = objItem.Path
weiter:
Set objShell = Nothing
Set objFolder = Nothing
Set objItem = Nothing
End Function
Option Explicit
Private Const Begriff As String = "Juni"
Private Sub DateienLesen()
Dim strPath$, strFile$, i&, arr()
If strPath = "" Then strPath = ShellVerzeichnisBrowser
If strPath <> "" Then
strPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
strFile = Dir(strPath & "*.jpg", vbNormal)
Do While strFile <> ""
If InStr(1, strFile, Begriff, vbTextCompare) > 0 Then
i = i + 1
ReDim Preserve arr(1 To 2, 1 To i)
arr(1, i) = strPath
arr(2, i) = strFile
End If
strFile = Dir
Loop
End If
If strPath <> "" Then
With Tabelle1
.UsedRange.ClearContents
.Cells(1, 1).Resize(UBound(arr, 2), 2) = Application.Transpose(arr)
End With
End If
End Sub
Private Function ShellVerzeichnisBrowser(Optional ByVal defaultPath = "") As String
Dim objItem As Object, objShell As Object, objFolder As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0&, "Bitte Verzeichnis anklicken", 0&, defaultPath)
If objFolder Is Nothing Then GoTo weiter
Set objItem = objFolder.Self
ShellVerzeichnisBrowser = objItem.Path
weiter:
Set objShell = Nothing
Set objFolder = Nothing
Set objItem = Nothing
End Function
If strPath <> "" and i>0 Then...
Option Explicit
Public Sub Main()
Dim strPfad As String
Dim strDatei As String
strPfad = "C:\Temp\"
strDatei = Dir(strPfad & "*Juni*.*")
'strDatei = Dir(strPfad & "*Juni*.xls*")
Do While strDatei <> ""
Workbooks.Open strPfad & strDatei
strDatei = Dir
Loop
End Sub
Option Explicit
Public Sub Main()
Dim strDatei As String
Dim strPfad As String
strPfad = "C:\Temp\"
strDatei = Dir$(strPfad & "*Juni*.xls*")
Do While strDatei <> ""
If InStr(strDatei, "abc") = 0 Then Workbooks.Open strPfad & strDatei
strDatei = Dir$
Loop
End Sub
strDatei = Dir(strPfad & "*" & mx0 & "*.*")
Sub alle_Dateien_Verzeichnis()
On Error GoTo Fehler
Dim Pfad$, Ext$, Datei$, SuchW$
Ext = ".xls*"
Pfad = "C:\Temp\" '**** mit \
SuchW = "*Juni*"
Datei = Dir(Pfad & SuchW & Ext)
Do While Len(Datei) > 0
Workbooks.Open Filename:=Pfad & Datei
'**
'Mach was damit
'**
'Workbooks(Datei).Close False
Datei = Dir() ' nächste Datei
Loop
Err.Clear
Fehler:
If Err.Number <> 0 Then MsgBox "Fehler: " & _
Err.Number & vbLf & Err.Description: Err.Clear
End Sub
Sub M_snb()
c00 = "D:\Beispiel\"
sn = Split(CreateObject("wscript.shell").exec("cmd /c dir " & c00 & "*Juni*.xls /b").stdout.readall, vbCrLf)
For Each it In sn
GetObject c00 & (it)
Next
End Sub
Option Explicit
Private Declare PtrSafe Function OemToCharA Lib "user32.dll" (ByVal lpszSrc As String, ByVal lpszDst As String) As Long
Private Const Begriff As String = "schu"
Public Function fncFromDuskTillDawn(ByVal strTMP As String) As String
Call OemToCharA(strTMP, strTMP)
fncFromDuskTillDawn = strTMP
End Function
Private Sub DateienLesen()
Dim arr, Pfad$
Pfad = "C:\Users\uwele\Downloads\Bilder Fotograf\Bilder Fotograf"
arr = Filter(Split(fncFromDuskTillDawn(CreateObject("Wscript.Shell").Exec("cmd /c dir """ & Pfad & """ /b").StdOut.ReadAll), vbCrLf), Begriff)
With Tabelle1
.UsedRange.ClearContents
.Cells(1, 1).Resize(UBound(arr) + 1, 1) = Pfad & "\"
.Cells(1, 2).Resize(UBound(arr) + 1, 1) = arr
End With
End Sub
$path = "C:\Temp"
$include = Read-Host "Dateiname MUSS enthalten"
$exclude = Read-Host "Dateiname DARF NICHT enthalten"
Get-ChildItem $path -Filter "*.xls*" |
Where-Object {$_.Name -like "*$include*" -and $_.Name -notlike "*$exclude*"} |
ForEach-Object {$excel.Workbooks.Open($_.FullName)}
Option Explicit
Public Sub Main()
Dim strSuch As String
Dim strEx As String
strSuch = "Juni"
strEx = "abc"
Shell "powershell.exe -ExecutionPolicy Bypass -File ""C:\Temp\FJ.ps1"" """ & strSuch & """ """ & strEx & """", vbHide 'vbNormalFocus
End Sub
param([string]$Include, [string]$Exclude)
$path = "C:\Temp"
Get-ChildItem $path -Filter "*.xls*" |
Where-Object {$_.Name -like "*$Include*" -and $_.Name -notlike "*$Exclude*"} |
ForEach-Object {Start-Process $_.FullName}
Sub M_snb()
With Application.FileDialog(1)
.AllowMultiSelect = True
.InitialFileName = "D:\SNB_\*juni*.xls*"
If .Show Then .Execute
End With
End Sub
Sub SearchAndOpenFiles()
Dim psCommand As String
Dim wsh As Object
Dim execObj As Object
Dim line As String
Dim searchPath As String
Dim searchPattern As String
Dim fDialog As FileDialog
Dim fileCount As Long
' === Suchmuster festlegen ===
searchPattern = "*abc*.xls*" ' Suchmuster anpassen
' === Ordnerauswahl-Dialog ===
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Bitte Suchordner auswählen"
.AllowMultiSelect = False
If .Show <> -1 Then
MsgBox "Suche abgebrochen.", vbInformation
Exit Sub
End If
searchPath = .SelectedItems(1)
End With
' === PowerShell-Befehl ===
' Gibt nur vollständige Dateipfade aus
psCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command " & _
"""Get-ChildItem -Path '" & searchPath & "' -Filter '" & searchPattern & "' -File -Recurse | " & _
"Select-Object -ExpandProperty FullName"""
' === PowerShell starten ===
Set wsh = CreateObject("WScript.Shell")
Set execObj = wsh.Exec(psCommand)
' === Jede gefundene Datei öffnen ===
fileCount = 0
Do While Not execObj.StdOut.AtEndOfStream
line = Trim(execObj.StdOut.ReadLine)
If Len(line) > 0 Then
fileCount = fileCount + 1
On Error Resume Next
Workbooks.Open Filename:=line, ReadOnly:=True
If Err.Number <> 0 Then
MsgBox "Fehler beim Öffnen: " & line, vbExclamation
Err.Clear
End If
On Error GoTo 0
End If
Loop
' === Ergebnis-Info ===
If fileCount = 0 Then
MsgBox "Keine Dateien gefunden.", vbInformation
Else
MsgBox fileCount & " Dateien geöffnet.", vbInformation
End If
End Sub
psCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command " & _
"""Get-ChildItem -Path '" & searchPath & "' -Filter '" & searchPattern & "' -File -Recurse | " & _
"Where-Object { $_.Name -notmatch '" & excludePattern & "' } | " & _
"Select-Object -ExpandProperty FullName"""