简体   繁体   English

如何在没有提示的情况下从 VBScript 关闭 Excel 文件?

[英]How to Close Excel file from VBScript without being prompted?

I have a VB Script that opens an Excel file and runs a macro.我有一个 VB 脚本,它打开一个 Excel 文件并运行一个宏。 I am trying to close this excel file(without saving any changes) without being prompted to save.我试图在没有提示保存的情况下关闭这个 excel 文件(不保存任何更改)。 I have set the 'Saved' property to true.我已将“已保存”属性设置为 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.我想在不保存和不提示的情况下关闭 excel 文件。

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

This should do it:这应该这样做:

objExcel.DisplayAlerts = False

objWorkbook.Close False 

你有没有尝试过:

    objWorkbook.Close False

Try this.试试这个。 This closes all the excel instances without asking to save.这将关闭所有 excel 实例而不要求保存。 You will however loose any unsaved data.但是,您将丢失任何未保存的数据。

Do While  True  
    Dim objExcel
    On Error Resume Next
    Set objExcel = GetObject(,"Excel.Application")
    If Err.Number <> 0 Then
        Exit Do
    End If
    On Error GoTo 0
    objExcel.DisplayAlerts = False
    objExcel.Quit
    Set objExcel = nothing
Loop 

Try this one, much easier!试试这个,简单多了!

FILENAME CMDS DDE 'Excel|system'; 

DATA _NULL_; 
FILE CMDS; 
PUT '[Workbook.Activate("FILENAME.XLS")]';
PUT "[SAVE()]";
PUT "[CLOSE("'"'"C:\FILENAME.XLS"'"'")]"; 
RUN;

Sorry this is using SAS.抱歉,这是使用 SAS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM