Terry Echols
New Member
- Joined
- Jul 14, 2015
- Messages
- 38
This code has worked for years until recently (this month). Now all of a sudden it is throwing the dreaded Runtime Error 1004 "Application-defined or Object-defined error"
I have tried everything I can think of but the error keeps showing up every time I run the code. Can anyone shed some light on this error from the code below, please.
I'm using Office 365
Thanks in advance...
Terry E
I have tried everything I can think of but the error keeps showing up every time I run the code. Can anyone shed some light on this error from the code below, please.
I'm using Office 365
Code:
Sub DataExtract()
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Dim i As Long
Dim j As Long
Dim k As Long
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim wb As Workbook
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(ThisWorkbook.Path & "\Statements\")
For Each objFile In objFolder.Files
If InStr(objFile, ".xls") Then
Workbooks.Open (objFile)
End If
Set wb = ActiveWorkbook
i = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row + 1
j = wb.Sheets("Statement").Cells(Rows.Count, "C").End(xlUp).Row
If wb.Sheets("Statement").Range("C13") <> vbNullString Then
wb.Sheets("Statement").Range("A13:F" & j).Copy
Sheet1.Range("B" & i).PasteSpecial xlPasteValuesAndNumberFormats
wb.Sheets("Statement").Range("I13:I" & j).Copy
Sheet1.Range("H" & i).PasteSpecial xlPasteValuesAndNumberFormats
k = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
wb.Sheets("Statement").Range("F6").Copy
Sheet1.Range("A" & i & ":A" & k).PasteSpecial
Application.CutCopyMode = False
End If
wb.Close
Next
Sheet1.Range("A1") = "All Invoices: " & Format(Date, "mmmm d, yyyy") & ", Week " & Format(Date, "ww")
'Align & Format Date text cell
Range("A1").RowHeight = 30
Range("A1").Font.Name = "Arial"
Range("A1").Font.Size = 16
Range("A1").IndentLevel = 1
Range("A1").VerticalAlignment = xlCenter
Range("A1").HorizontalAlignment = xlGeneral
MsgBox "Task Complete!"
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Thanks in advance...
Terry E