Hi
I have this piece of code which works fine however i need to open a workbook first before it runs the rest of the code.
Code:
Sub Get_Dealer_Count()
Dim ws As Worksheet
Dim wb As Workbook
Dim wb1 As Workbook
Dim xlCalc As XlCalculation
Dim strFldr As String
Dim strFile As String
Application.ScreenUpdating = False
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)"
.Value = .Value
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
Does anyone know how?
Thanks
Jeskit