Hi All,
have been running a very simple macro for the last few months which very simple pulls in a file from another location and pastes some data. It then Fetches another file and at this point it seems to cause excel to crash and the "excel has stopped working" error.
This error has only been coming up in the last week prior to that it was running smoothly a version of the code as per below, any suggestions welcome
Thanks,
David
have been running a very simple macro for the last few months which very simple pulls in a file from another location and pastes some data. It then Fetches another file and at this point it seems to cause excel to crash and the "excel has stopped working" error.
This error has only been coming up in the last week prior to that it was running smoothly a version of the code as per below, any suggestions welcome
Code:
Sub SolicitorPMTS()
' FOLDER VARIABLES
Dim ThisYear As String
Dim ThisMonth As String
Dim LastMonth As String
Dim ThisLetter As String
Dim ThisFolder As String
Dim Folderyear As String
Dim FolderPath As String
Dim fso As New FileSystemObject
Dim Path As String
Folderyear = year(DateAdd("m", -0, Date))
'USED FOR LOOKUP TO PREVIOUS MONTH
ThisYear = Format(DateAdd("m", -0, Date), "yy")
ThisMonth = Format(DateAdd("m", -0, Date), "mmm")
'THIS MONTH LETTERS
Select Case ThisMonth
Case Is = "Jan"
ThisLetter = "a."
Case Is = "Feb"
ThisLetter = "b."
Case Is = "Mar"
ThisLetter = "c."
Case Is = "Apr"
ThisLetter = "d."
Case Is = "May"
ThisLetter = "e."
Case Is = "Jun"
ThisLetter = "f."
Case Is = "Jul"
ThisLetter = "g."
Case Is = "Aug"
ThisLetter = "h."
Case Is = "Sep"
ThisLetter = "i."
Case Is = "Oct"
ThisLetter = "j."
Case Is = "Nov"
ThisLetter = "k."
Case Is = "Dec"
ThisLetter = "l."
End Select
FolderPath = "File Location"
BSFolderPath = "File Location"
wd = WorksheetFunction.WorkDay(Date, -1)
FolderPath = "File Location"
BSHalfFileName = "Bank Balances - "
HalfFileName = "XXX - Daily Completions Funding - "
ThisFolder = ThisLetter & ThisMonth & "-" & ThisYear
Filename = HalfFileName & Format(Date, "dd") & ThisMonth & ThisYear & ".xls"
bsfilename = BSHalfFileName & Format(Date, "dd") & ThisMonth & Folderyear & ".xlsx"
prevfilename = HalfFileName & Format(wd, "dd") & ThisMonth & ThisYear & ".xls"
Path = FolderPath & Folderyear & "\" & ThisFolder
bspath = BSFolderPath & Folderyear & "\" & ThisFolder
Workbooks("EXCELFILE.xlsb").Activate
Worksheets("Solicitor Payments").Activate
Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Workbooks("EXCELFILE.xlsb").Activate
Range("l3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
'Import Today's Payments
Workbooks.Open Path & "\" & Filename
Windows(Filename).Activate
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Workbooks("EXCELFILE.xlsb").Activate
Sheets("Solicitor Payments").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Convert To Number
Range("D3").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.NumberFormat = "General"
.Value = .Value
End With
'Import Yesterday's Payments
Workbooks.Open Path & "\" & prevfilename
Windows(prevfilename).Activate
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Workbooks("TOM 3.xlsb").Activate
Sheets("Solicitor Payments").Select
Range("l3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Convert To Number
Range("o3").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.NumberFormat = "General"
.Value = .Value
End With
Workbooks.Open bspath & "\" & bsfilename
ActiveSheet.Range("a8").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Workbooks("EXCELFILE.xlsb").Activate
Worksheets("INPUT_Bank Statement").Activate
Range("a6").Select
ActiveSheet.Paste
Worksheets("Daily Balances").Activate
Range("zz3").Select
Selection.End(xlToLeft).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.Offset(0, 1).Select
ActiveSheet.Paste
Range("zz3").Select
Selection.End(xlToLeft).Select
Selection.Offset(0, -1).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Calculate
End Sub
Thanks,
David