Last year I stumbled across this code I've been using since. Last year I didn't run into any issues, but this year all of a sudden I'm running into issues that I've limited the cause to involving my work network drives. I say this because when I point the macro below to a local drive it works every time. I think the issue centers around others staff being in the file and the macro being able to handle opening the file in read only format. Normal the macro successfully opens the file. However there has been instances when the excel files become locked due to the network, and it shows a staff person being in the file when it is not the case. What I was hoping was if someone could show me where I could include some code that would prevent the macro from bombing out due network instability. Network instability that cause a file remaining to be lock which causes the macro to bomb out I haven't been able to resolve with our network administer. His only remedy has be to click notify and wait patiently until the file becomes available again. Even when I do that something remains suspended with the file which has result in me copying the file to another location and pointing the macro to another spot on my work network.
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim a, SC As Integer
Dim mergeObj, dirObj, filesObj, everyObj As Object
Application.AskToUpdateLinks = False
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'/ This section is where I indicate the path on the network in which I wish to capture files.
sFilePath = ThisWorkbook.Worksheets(1).Range("B23").Text
Set dirObj = mergeObj.Getfolder(sFilePath)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Application.EnableEvents = False
Set bookList = Workbooks.Open(everyObj)
bookList.Worksheets(1).Activate
Range("A2:CG" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets("Allstaff").Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
bookList.Close savechanges:=False
Next
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim a, SC As Integer
Dim mergeObj, dirObj, filesObj, everyObj As Object
Application.AskToUpdateLinks = False
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
'/ This section is where I indicate the path on the network in which I wish to capture files.
sFilePath = ThisWorkbook.Worksheets(1).Range("B23").Text
Set dirObj = mergeObj.Getfolder(sFilePath)
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Application.EnableEvents = False
Set bookList = Workbooks.Open(everyObj)
bookList.Worksheets(1).Activate
Range("A2:CG" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets("Allstaff").Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
bookList.Close savechanges:=False
Next