This oughta do the trick, let me know if you have any questions with the coding :
Code:Dim IntCount As Integer, ObjExcel As Object Set ObjExcel = GetObject(, "Excel.application") With ObjExcel .Workbooks.Add .Workbooks(2).Worksheets(1).Select 'You'll need to select the wotrkbook before carrying out work on it '.Visible = False 'you won't need this, it's automatically set to be hidden 'by default, and you have to enter this as true for otherwise For IntCount = 0 To Int(Data2.Recordset.Fields.Count - 1) DoEvents Cells(1, IntCount + 1).Value = Data2.Recordset.Fields(IntCount).Name Next Range("A2").CopyFromRecordset Data2.Recordset .Cells(1, 1).CurrentRegion.EntireColumn.AutoFit .Sheets("Sheet1").Name = strReportName .displayalerts = False 'This will stop any messages about overwiting and file being saved 'from popping up on your screen and may be to do with your problem. .ActiveWorkbook.SaveAs FileName:="C:\Windows\Temp\XlFileName.Xls" 'Course, this is the 2nd part of the error - your old code just shows 'a path : ActiveWorkbook.SaveAs FileName:="C:\Windows\Temp\" and doesn't 'specify a filename to save this as !!!! .Workbooks.Close .Quit End With Set ObjExcel = Nothing




Reply With Quote