hey guys I'm in need of your help,
my Code keep crashing and i Donno why. i have on one sheet table that i got from SQL
and I have imported the table to the sheet called "DataSrc" ,now when I'm trying to loop through the table
its crashing in random places i get the 1004 error.
i need to merge all .xls file from the same Clint to one excel with sheets
its opening the file starting to run like it's all good then all of a sudden crash please help me.
my Code keep crashing and i Donno why. i have on one sheet table that i got from SQL
and I have imported the table to the sheet called "DataSrc" ,now when I'm trying to loop through the table
its crashing in random places i get the 1004 error.
i need to merge all .xls file from the same Clint to one excel with sheets
its opening the file starting to run like it's all good then all of a sudden crash please help me.
Code:
Sub DoFolder()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim MyPath, MyType As String
Dim MyDate As Date
Dim strFilename As String
Dim Name As String
Dim i As Long
i = 2
With ThisWorkbook.Sheets("DataSrc")
Application.DisplayAlerts = False
Set wbDst = Workbooks.Add
Do Until .Range("E" & i) = ""
MyPath = .Range("G" & i)
MyDate = .Range("B" & i)
If Range("C1") <= MyDate Then
If .Range("G" & i) = .Range("G" & i - 1) Or i = 2 Then
Zibi:
Application.EnableEvents = False
Set wbSrc = Workbooks.Open(MyPath)
Set wsSrc = wbSrc.Worksheets(1)
ActiveSheet.Name = .Range("C" & i)
wsSrc.Copy After:=wbDst.Worksheets(wbDst.Worksheets.Count)
wbSrc.Close False
Else
wbDst.Worksheets("Sheet1").Delete
Name = .Range("A" & i)
wbDst.SaveAs "C:\Users\Elia.Peretz\Desktop\גירסאות פרוייקט\27\" & Name & " & " & i & ".xlsx "
wbDst.Close True
Set wbDst = Workbooks.Add
GoTo Zibi
End If
End If
i = i + 1
Loop
wbDst.Close False
End With
End Sub