I have a run-time error '1004': Application - defined or object-defined error with my codes.
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
Dim strWSName As String
strWSName = InputBox("Enter the file path of Excel Files to merge")
If strWSName <> "" Then
Set dirObj = mergeObj.GetFolder(strWSName)
Range("A1").Value = "Item"
Range("B1").Value = "Description"
Range("C1").Value = "Quality"
Set fileObj = dirObj.Files
For Each everyObj In fileObj
Set bookList = Workbooks.Open(everyObj)
Dim rayong As Integer, suzhou As Integer, shenyang As Integer, japan As Integer
rayong = InStr(1, everyObj, "RAYONG", vbTextCompare)
suzhou = InStr(1, everyObj, "SZ", vbTextCompare)
shenyang = InStr(1, everyObj, "Shenyang", vbTextCompare)
japan = InStr(1, everyObj, "JPN", vbTextCompare)
If rayong = 95 Then
Range("A2:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
ElseIf suzhou = 100 Then
Workbooks.Open(everyObj).Activate
Range("B2:B" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Workbooks.Open(everyObj).Activate
Range("I2:I" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial
Workbooks.Open(everyObj).Activate
Range("H2:H" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("C65536").End(xlUp).Offset(1, 0).PasteSpecial
ElseIf shenyang = 95 Then
ActiveWorkbook.Sheets("WMSInventory").Activate
Range("A2:A" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
ActiveWorkbook.Sheets("WMSInventory").Activate
Range("B2:B" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial
ActiveWorkbook.Sheets("WMSInventory").Activate
Range("D2:D" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("D65536").End(xlUp).Offset(1, 0).PasteSpecial
ElseIf japan = 88 Then
Workbooks.Open(everyObj).Activate
Range("A2:A" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Workbooks.Open(everyObj).Activate
Range("O2:O" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial
Workbooks.Open(everyObj).Activate
Range("B2:B" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("C65536").End(xlUp).Offset(1, 0).PasteSpecial
End If
Application.CutCopyMode = False
bookList.Close
Next
Else
MsgBox "No FilePath Provided! Re-Open this excel to put complete filepath."
End If
End Sub
Please help. :(