Question : MS Access 2007 create csv file - quit excel object without asking to save.

I have the following code creating a csv file which works fine.

Howver on the last line xlobj.quit it asks if I want to save or not.

I would like to not have it ask this but carn't stop it.

Appreciate any ideas.

Note a adp database looking as MSSQL.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Dim con As Object
Set con = Application.CurrentProject.Connection
 
Dim rstExcel As Object
Dim strSQLExcel As String
 
Dim xlObj As Object
Dim Sheet As Object
 
strSQLExcel = "SELECT * From Customers"
 
Set rstExcel = CreateObject("ADODB.Recordset")
rstExcel.Open strSQLExcel, con, 1   ' 1 = adOpenKeyset
 
Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Add
Set Sheet = xlObj.ActiveWorkbook.Sheets(1)
 
Sheet.Range("A1").CopyFromRecordset rstExcel  
 
Dim strCSVFile As String
strCSVFile = "C:\Test.txt"
 
Sheet.SaveAs strCSVFile, xlCSV
 
rstExcel.Close
Set rstExcel = Nothing
 
xlObj.Quit    '**********
 
Set xlObj = Nothing
 
Set con = Nothing

Answer : MS Access 2007 create csv file - quit excel object without asking to save.

Try adding "xlObj.ActiveWorkbook.Close SaveChanges:=False" at line 28.
Random Solutions  
 
programming4us programming4us