Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Close Excel file from VBScript without being prompted?

Tags:

excel

vbscript

I have a VB Script that opens an Excel file and runs a macro. I am trying to close this excel file(without saving any changes) without being prompted to save. I have set the 'Saved' property to true. But I am still prompted with the Save window. I read somewhere that I have to disable the macro. Not sure how? I would like to close the excel file without saving and without prompting.

Dim objExcel, objWorkbook 

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("c:\aaa\Test.xls")
objExcel.Visible = True
objExcel.Run "Extract_PLStatements"
objworkbook.Saved = True
objWorkbook.Close

objExcel.Quit

Set objWorkbook = Nothing
Set objExcel = Nothing

WScript.Quit
like image 656
stackuser Avatar asked Jan 07 '14 18:01

stackuser


People also ask

How do I stop Excel from prompting?

In Excel, select Edit Links in the Queries & Connections group on the Data tab. Click Startup Prompt. Click the Don't display the alert and don't update automatic links option.

How do I turn off Save Changes prompt when I close a workbook in Excel?

Summary. In Microsoft Excel, you can create a Microsoft Visual Basic for Applications (VBA) macro that suppresses the Save Changes prompt when you close a workbook. This can be done either by specifying the state of the workbook Saved property, or by suppressing all alerts for the workbook.


2 Answers

This should do it:

objExcel.DisplayAlerts = False

objWorkbook.Close False 
like image 153
Tim Williams Avatar answered Oct 17 '22 21:10

Tim Williams


Have you tried:

    objWorkbook.Close False
like image 2
Joe Avatar answered Oct 17 '22 22:10

Joe