Sub test()
Application.ScreenUpdating = False
sPfad = "c:/temp"
If Right(sPfad, 1) <> "/" Then
sPfad = sPfad & "/"
End If
sDatei = Dir(sPfad & "*.xls")
Do While sDatei <> ""
Workbooks.Open sPfad & sDatei
AKTION
Workbooks(Workbooks.Count).Close savechanges:=True
sDatei = Dir()
Loop
Application.ScreenUpdating = True
End Sub
Im Wss kommt die Fehlermeldung 'Dateiname oder -nummer falsch' :-(Sub test()
Dim meArDateien() As String
Dim i As Integer
Dim sDatei$, sPfad$
Dim oWB As Workbook
sPfad = "C:\temp"
If Right(sPfad, 1) <> "\" Then
sPfad = sPfad & "\"
End If
sDatei = Dir$(sPfad & "*.xls")
Do While sDatei <> ""
ReDim Preserve meArDateien(i)
meArDateien(i) = sPfad & sDatei
sDatei = Dir$()
Loop
If i > 0 Then
Application.ScreenUpdating = False
For i = 0 To UBound(meArDateien)
Set oWB = Workbooks.Open(sPfad & sDatei)
AKTION
oWB.Close savechanges:=True
Next i
Application.ScreenUpdating = True
End If
End Sub
Gruß TinoSub test()
Dim meArDateien() As String
Dim i As Integer
Dim sDatei$, sPfad$
Dim oWB As Workbook
sPfad = "C:\temp"
If Right(sPfad, 1) <> "\" Then
sPfad = sPfad & "\"
End If
sDatei = Dir$(sPfad & "*.xls")
Do While sDatei <> ""
ReDim Preserve meArDateien(i)
meArDateien(i) = sPfad & sDatei
i = i + 1
sDatei = Dir$()
Loop
If i > 0 Then
Application.ScreenUpdating = False
For i = 0 To UBound(meArDateien)
Set oWB = Workbooks.Open(sPfad & sDatei)
AKTION
oWB.Close savechanges:=True
Next i
Application.ScreenUpdating = True
End If
End Sub
Gruß TinoSub test()
Dim meArDateien() As String
Dim i As Integer
Dim oWB As Workbook
Dim FSO As Object, SourceFolder As Object, FileItem As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder("C:\temp") 'Ordner angeben
For Each FileItem In SourceFolder.Files
If LCase(FileItem) Like "*.xls" Then 'Filter
meArDateien(i) = FileItem
i = i + 1
End If
Next FileItem
If i > 0 Then
Application.ScreenUpdating = False
For i = 0 To UBound(meArDateien)
Set oWB = Workbooks.Open(meArDateien(i))
' AKTION
oWB.Close savechanges:=True
Next i
Application.ScreenUpdating = True
End If
Set FSO = Nothing: Set SourceFolder = Nothing
End Sub
Gruß Tino