Hi
The piece of code below keeps stopping and display and error saying "Run time error 1004: Application-defined or Object-defined error"
The piece of code below should open a specific workbook, open the sheet, run the loop (which opens all the files in a folder and perofrms a counta formula) then paste the results in the workbook opened.
Code:
Sub Get_Dealer_Count()
Dim ws As Worksheet
Dim wb As Workbook
Dim xlCalc As XlCalculation
Dim strFldr As String
Dim strFile As String
Application.ScreenUpdating = False
Application.Workbooks.Open ("c:\Documents and settings\SeymourJ\My Documents\Extract_Size_Checker_test.xls")
Set ws = Sheets("Dealer Extracts")
ws.Range("F17:H38").ClearContents
ws.Range("F17:H17").Value = [{"Directory", "Filename", "Row Number"}]
strFldr = ("C:\Production2\ATX\Extracts\201001\DealerData")
strFile = Dir(strFldr & "\*.csv*")
If Len(strFile) > 0 Then
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
End With
Do
Set wb = Workbooks.Open(Filename:=strFldr & "\" & strFile)
With ws.Cells(ws.Rows.Count, "F").End(xlUp)
.Offset(1).Value = strFldr
.Offset(1, 1).Value = strFile
.Offset(1, 2).Formula = "=COUNTA('[" & wb.Name & "]" & wb.Sheets(1).Name & "'!$A:$A)"
End With
wb.Close False
strFile = Dir
Application.StatusBar = strFile
Loop Until Len(strFile) = 0
End If
With ws.Range("F17:H17")
.Font.Bold = False
.EntireColumn.AutoFit
End With
End Sub
However when it gets to this bit:
Code:
.Offset(1, 2).Formula = "=COUNTA('[" & wb.Name & "]" & wb.Sheets(1).Name & "'!$A:$A)"
End With
It stops and displays the error mentioned above. I have tried it without the opening a workbook bit and it works fine but when i add the piece of code to open an exisiting workbook
Code:
Application.Workbooks.Open ("c:\Documents and settings\SeymourJ\My Documents\Extract_Size_Checker_test.xls")
it falls over.
Can anyone help me??
Thanks
jeskit