i have 4 excel files (city.xls, rule.xls,adv.xls and maping.xls), where all of excel files being opened. how to force close only one file (Ex: maping.xls) with taskkill in batch/CMD programing?
问问题
2801 次
2 回答
3
Taskkill 将消除一个进程及其所有窗口。你的工作簿可以在同一个excel实例下全部打开,所以taskkill不能做你需要的。
您可以使用 AutoIt、nircmd、cmdow 等一些工具来关闭您需要的窗口,但您必须处理对话框要求保存工作簿的可能性。
这是一个批处理文件(只需保存为 .cmd 并更改 xlsx 文件),其中包含一个脚本部分,用于搜索工作簿并在没有对话框的情况下关闭它。没有防弹,只能在打开工作簿的用户的同一会话下工作,而只是一个起始示例。
@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************
rem call javascript part of batch file
cscript //nologo //e:Javascript "%~dpnx0" /workbook:"j:\wherever\myWorkbook.xlsx"
rem End of batch area. Ensure batch ends execution before reaching
rem javascript zone
exit /b
@end
// **** Javascript zone *****************************************************
if (!WScript.Arguments.Named.Exists('workbook')) {
// if no workbook argument, no work to do
WScript.Quit(1);
};
// retrieve workbook name
var workbook = WScript.Arguments.Named.Item('workbook');
var exitCode = 0;
try {
// search for workbook application
var wb = GetObject(workbook);
// get handle to application containing workbook
var app = wb.Application;
// close workbook. Ask for save = false
wb.Close( false );
// if no more workbooks open in application, close it
if (app.Workbooks.Count == 0){
app.Quit();
};
} catch(e){
// some kind of problem with objects
// WScript.Echo( e.description );
exitCode = 2;
};
app =null;
wb =null;
WScript.Quit(exitCode);
于 2013-10-29T11:58:04.960 回答
1
来自 Taskkill 的帮助 (taskkill /?)
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE 无标题*"
于 2013-10-29T07:45:49.597 回答