Ik heb een macro ooit eens van het web gehaald, die in een directory het eerste bestand opent en daar iets mee doet, het bestand sluit en het volgende opent enzovoorts tot hij alle bestanden gehad heeft.
Maar...............hij doet het niet meer en ik kom er niet uit waar de fout zit, graag jullie hulp
Sub OpenEveryDirFile()
++++++++++++++++++++++++++++
'met dank aan Steve Aprahamian
++++++++++++++++++++++++++++
Dim strPath As String
Dim lFile As Long
Dim wkb As Workbook
Dim Source As String
Application.ScreenUpdating = False
'zoek de juiste map op
strPath = Application.GetOpenFilename _
(Title:="Choose file in Folder to Document")
If strPath = "False" Then
MsgBox "Canceled by User"
Exit Sub
End If
Do Until Right(strPath, 1) = "\"
strPath = Mid(strPath, 1, Len(strPath) - 1)
Loop
With Application.FileSearch
.NewSearch
.LookIn = strPath
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() < 1 Then
MsgBox "There were no files found."
Exit Sub
End If
For lFile = 1 To .FoundFiles.Count
Set wkb = Workbooks.Open(FileName:=.FoundFiles(lFile), _
updatelinks:=False, ReadOnly:=True, _
IgnoreReadOnlyRecommended:=True)
' doe hier iets (een andere macro)
wkb.Close (False)
Next lFile
End With
Set wkb = Nothing
ActiveWorkbook.Close SaveChanges:=True
End Sub
Maar...............hij doet het niet meer en ik kom er niet uit waar de fout zit, graag jullie hulp
Sub OpenEveryDirFile()
++++++++++++++++++++++++++++
'met dank aan Steve Aprahamian
++++++++++++++++++++++++++++
Dim strPath As String
Dim lFile As Long
Dim wkb As Workbook
Dim Source As String
Application.ScreenUpdating = False
'zoek de juiste map op
strPath = Application.GetOpenFilename _
(Title:="Choose file in Folder to Document")
If strPath = "False" Then
MsgBox "Canceled by User"
Exit Sub
End If
Do Until Right(strPath, 1) = "\"
strPath = Mid(strPath, 1, Len(strPath) - 1)
Loop
With Application.FileSearch
.NewSearch
.LookIn = strPath
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() < 1 Then
MsgBox "There were no files found."
Exit Sub
End If
For lFile = 1 To .FoundFiles.Count
Set wkb = Workbooks.Open(FileName:=.FoundFiles(lFile), _
updatelinks:=False, ReadOnly:=True, _
IgnoreReadOnlyRecommended:=True)
' doe hier iets (een andere macro)
wkb.Close (False)
Next lFile
End With
Set wkb = Nothing
ActiveWorkbook.Close SaveChanges:=True
End Sub