The thread title says it all. Could anyone suggest what I should be checking now? 
I run the code below (BTW I removed all speed hacks incl. screen updating off to see where it was going wrong), the code gets partway through the files and suddenly stops with the wbCurrentWB open. No error message. Just stops.
WHAT I HAVE TRIED SO FAR:
I have run the code a few times and it gets the above problem every time.
The code stops on a different workbook each time (so that rules out anything funny to do with the .xlsx files)
All workbooks have the worksheet that is being updated.
I am testing this code on a local machine using a copy of the Dat File directory. (So that rules out something wrong with the WB in use code)
Option Explicit
Private Const strDir_Datafile = "C:\dat\"
Private strFileName As String
Private Const strNtabEmployee = "employee5"
Public Sub DataFilesCollection_EditAll()
' used to make batch edits to all Dat Files. Use with care!
Dim wbCurrentWB As Workbook
Dim dtmTimer As Date
Application.DisplayAlerts = True
On Error GoTo 0
dtmTimer = Now()
strFileName = Dir(strDir_Datafile & "*.xlsx")
Do While strFileName <> ""
Set wbCurrentWB = Workbooks.Open(strDir_Datafile & strFileName)
With wbCurrentWB
If .ReadOnly = True Then 'don't update if another user has wb open
Debug.Print strFileName & "could not update"
.Close SaveChanges:=False
Else
.Worksheets(strNtabEmployee).Range("E2").Value = Mid(strFileName, 4, 11) 'add missing value
.Save
.Close SaveChanges:=True
End If
End With
strFileName = Dir()
Loop
MsgBox "Done in " & Format(Now() - dtmTimer, "#.###") & " seconds"
MsgBox "Don't forget to check the Immediate Window now!"
Debug.Print "CHECK NOW"
End Sub
Bookmarks