after WScript.Echo "objWorkbook.Close" , I get a message if i want to save my changes to the file !!!!
I thought the file should have been brand new and the previous version already been deleted ---- Another blind spot that I cant figure out
I thought the file should have been brand new and the previous version already been deleted ---- Another blind spot that I cant figure out
Code:
'Microsoft Excel Automation Basics
dim filesys
dim sFilename
Dim sConnectionString
Dim round ,RecCounter
Dim value(10)
'sConnectionString =
' Create connection object
Do While (true)
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set connect = CreateObject("ADODB.Connection")
connect.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\srahami\Desktop\TEST.accdb"
connect.Open
sql="SELECT Table1.Field4, Table1.Field5, Table1.Field6 FROM Table1 WHERE Table1.ID=" & Cstr(1+ (round mod 10) )
round =round +1
WScript.Echo sql
Set resultSet = connect.Execute(sql)
On Error Resume Next
resultSet.MoveFirst
'WScript.Echo "STARTS{"
RecCounter =0
Do While Not resultSet.eof
WScript.Echo( resultSet(0) &","& resultSet(1) &","& resultSet(2) )
RecCounter = RecCounter +1
if (RecCounter = 1 ) then
value(0) = resultSet(0)
value(1) = resultSet(1)
value(2) = resultSet(2)
End if
resultSet.MoveNext
Loop
'WScript.Echo "}END"
WScript.Echo(value(0))
WScript.Echo(value(1))
WScript.Echo(value(2))
WScript.Echo "___________________"
resultSet.Close
connect.Close
Set connect = Nothing
sFilename = "C:\Users\srahami\Desktop\OUTPUT.xlsx"
WScript.Echo( "**** File:" & sFilename )
Set filesys = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
If filesys.FileExists(sFilename) Then
filesys.DeleteFile sFilename
WScript.Sleep(1000)
WScript.Echo "FILE DELETD " & sFilename
ELSE
WScript.Echo "FILE NOT FOUND TO BE DELETED " & sFilename
End if
Set objWorkbook = objExcel.Workbooks.Add
objExcel.Cells(1,1).Value = value(0)
objExcel.Cells(1,2).Value = value(1)
objExcel.Cells(1,3).Value = value(2)
objExcel.Cells(1,4).Value = Now()
'WScript.Echo "- - - - - -"
'For I = 1 to 4
' WScript.Echo I,objExcel.Cells(1,I).Value
'NEXT
WScript.Echo "==============="
WScript.Echo "objWorkbook.SaveAs sFilename"
objWorkbook.SaveAs sFilename
WScript.Echo "objWorkbook.Close"
WScript.Sleep(1000)
objWorkbook.Close
WScript.Echo "STEP521"
objExcel.Quit
WScript.Echo( sFilename & " created " & Now())
WScript.Echo "Set objExcel = Nothing"
Set objExcel = Nothing
WScript.Echo "Set objWorkbook = Nothing"
Set objWorkbook = Nothing
WScript.Echo "STEP7"
WScript.Sleep(10000)
Loop
'release objects