# vbscript (not VBA) Close excel ithout saving



## dh_ander (Nov 8, 2007)

I use a vbscript to check several excel files (just checking no changes) after we upgraded to office 2003, the script now keeps asking if i want to save the changes in the excel sheet which i obiously don't want.


```
Option Explicit

Const vbNormal = 1

DIM oXL, oWB
DIM row, col
DIM Member, Group
DIM fso, OutputFile, InputFile
DIM InputPathAndFile
DIM WerkFolder
DIM RegelsVerwerkt, ExcelSheetsVerwerkt


'--- Vul variabelen ---
SET fso = createobject("Scripting.FileSystemObject")
SET OutputFile = fso.createtextfile("LegeRegels.txt", True)

RegelsVerwerkt = 0
ExcelSheetsVerwerkt = 0
col = 1

'--- Haal het path op waar het script draait
WerkFolder = WScript.ScriptFullName
WerkFolder = Left(WerkFolder, InstrRev(WerkFolder, "\"))

'--- Controleren of InputFile bestaat ---
IF Not fso.FileExists(WerkFolder & "\dir.txt") THEN
   Wscript.echo "Invoerbestand: DIR.TXT bestaat niet!"
   wscript.quit
ELSE
   '--- InputFile definieren ---
   SET InputFile = fso.OpenTextFile("dir.txt",1,FALSE)
END IF


SET oXL = CreateObject("Excel.Application")

'--- Set Window Properties ---
oXL.WindowState = vbNormal 'Normal
oXL.Height = 300           'Height
oXL.Width = 400            'Width
oXL.Left = 40              'X-Position
oXL.Top = 20              'Y-Position
oXL.Visible = true        'show window


'--- Loop over InputFile "dir.txt" ---
DO UNTIL InputFile.AtEndOfStream
   InputPathAndFile = InputFile.ReadLine

   '--- Open Excelsheet en selecteer tabblad "Output"
   SET oWB = oXL.WorkBooks.Open(InputPathAndFile)
   SET oWB = oXL.ActiveWorkBook.WorkSheets("Output")
   oWB.Activate

   '--- Loop over regels in "output" tabblad in ExcelSheet start bij rij 1 ---
   row = 1
   DO
      Member = Cstr(oWB.Cells(row,col).Value)
      Group = Cstr(oWB.Cells(row,col+1).Value)
      IF Member = "" and Group = "" THEN
         row = row + 1
         Member = Cstr(oWB.Cells(row,col).Value)
         Group = Cstr(oWB.Cells(row,col+1).Value)
         IF Member <> "" and Group <> "" THEN
            '--- Schrijf output weg
            OutputFile.writeline InputPathAndFile 
         END IF
      END IF
      row = row + 1
   LOOP until Group = ""

   ExcelSheetsVerwerkt = ExcelSheetsVerwerkt + 1

   oXL.WorkBooks.close
  

LOOP

OutputFile.close
InputFile.close

MsgBox("Het script is klaar. Verwerkt zijn: " & CHR(13) & CHR(13) & "Excel Sheets   : " & CSTR(ExcelSheetsVerwerkt))

oXL.Quit()
SET oXL = Nothing
```

my guess was that the problem is in the line:


```
oXL.WorkBooks.close
```
hoever i have tried things like


```
oXL.WorkBooks.close false
```
but it all doesn't work, any other suggestions?

thanks in advance as alway's


----------



## dh_ander (Nov 9, 2007)

no suggestions?


----------



## Norie (Nov 9, 2007)

David

Why not try this.

```
oXL.DisplayAlerts = False
```
Or this.
	
	
	
	
	
	



```
oXL.Workbooks.Close(False)
```


----------



## dh_ander (Nov 12, 2007)

Thanks for your reply.

The first suggestions works, the second gives a VBS error (wrong number of arguments)

thanks


----------

