vbscript (not VBA) Close excel ithout saving

dh_ander

Board Regular
Joined
Jul 31, 2006
Messages
119
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.

Code:
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:

Code:
oXL.WorkBooks.close
hoever i have tried things like

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

thanks in advance as alway's
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
David

Why not try this.
Code:
oXL.DisplayAlerts = False
Or this.
Code:
oXL.Workbooks.Close(False)
 
Upvote 0
Thanks for your reply.

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

thanks
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,750
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top