小编Cas*_*thy的帖子

在excel退出时忽略"你想保存"框吗?

我有一个脚本打开excel文件并运行宏,然后退出该文件.由于文件处于只读模式,并且脚本对文件进行临时更改,因此当脚本调用myExcelWorker.Quit()excel询问我是否要保存更改时,必须单击"否".有没有办法退出程序并跳过此框?

' Create a WshShell to get the current directory
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application") 

myExcelWorker.Visible = True

' Tell Excel what the current working directory is 
' (otherwise it can't find the files)
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = myExcelWorker.DefaultFilePath
strPath = WshShell.CurrentDirectory
myExcelWorker.DefaultFilePath = strPath

' Open the Workbook specified on the command-line 
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\BugHistogram_v2.xlsm"

Set oWorkBook …
Run Code Online (Sandbox Code Playgroud)

vbscript excel vba excel-vba

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1

vbscript ×1