Hello all,
I had a code on excel 2003 which opened the workbooks done something closed them and then moved to the next one. this was the code:
Dim i As Integer, wb As Workbook
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = ActiveWorkbook.Path
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
Next i
End With
Now I am using excel 2010 and I found this helpful code posted by "RoyUK" and replaced my code.
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
sPath = ActiveWorkbook.Path 'location of files
ChDir sPath
sFil = Dir("*.xls") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through
Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the file
Call Control
oWbk.Close True 'close the workbook, saving changes
sFil = Dir
Loop '
It finds files in the activeworkbook folder, open it, do what i want it to do, BUT instead of moving to the next file after closing it. It just reopen the same file and try to do the same stuff again.
How should I change it so that it will move to the file in the folder ?
Thanks!
Bookmarks