有人可以帮助我使用这个脚本来关闭/终止SAP Workbook吗?这工作很长时间,直到公司将MS Office更新为新版本(MS Office 365 ProPlus)。此代码的目的是强制关闭某些SAP生成的电子表格,这些电子表格在提取SAP报告时会自动弹出。这个旧代码在此论坛之前由@ScriptMan共享。
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable();
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
基于我的初始检查,问题出现在这一部分,因为它不断循环(通过在循环后放置一个MsgBox来检测它)。我注意到新版本的Excel 2016使生成的电子表格成为新的实例/会话,就像它继续在进程选项卡中创建新的Excel.exe一样。
SAP_Workbook = "ZZFRAR080_EXTRACTED.XLSX"
on error resume next
do
err.clear
Set xclApp = GetObject(, "Excel.Application")
If Err.Number = 0 Then exit do
'msgbox "Wait for Excel session"
wscript.sleep 2000
loop
do
err.clear
Set xclwbk = xclApp.Workbooks.Item(SAP_Workbook)
If Err.Number = 0 Then exit do
wscript.sleep 2000
loop
on error goto 0
Set xclSheet = xclwbk.Worksheets(1)
xclApp.Visible = True
xclapp.DisplayAlerts = false
xclapp.ActiveWorkbook.Close
Set xclwbk = Nothing
Set xclsheet = Nothing
'xclapp.Quit
set xclapp = Nothing
答案 0 :(得分:0)
您可以尝试以下方法:
SAP_Workbook = "ZZFRAR080_EXTRACTED.XLSX"
Set Wshell = CreateObject("WScript.Shell")
Wshell.Run "c:\tmp\SAP_Workbook_Close.vbs" & " " & SAP_Workbook, 1, False
. . .
SAP_Workbook_Close.vbs:
myFileName = wscript.arguments(0)
on error resume next
do
err.clear
Set xclApp = GetObject(, "Excel.Application")
'xclApp.WindowState = -4140 'xlMinimized
If Err.Number = 0 Then exit do
'msgbox "Wait for Excel session"
wscript.sleep 2000
loop
do
err.clear
Set xclwbk = xclApp.Workbooks.Item(myFileName)
'xclApp.WindowState = -4140 'xlMinimized
If Err.Number = 0 Then exit do
'msgbox "Wait for SAP workbook"
wscript.sleep 2000
loop
on error goto 0
Set xclSheet = xclwbk.Worksheets(1)
xclapp.ActiveWorkbook.Close
xclApp.Visible = True
xclapp.DisplayAlerts = false
'xclApp.WindowState = -4143 'xlNormal
Set xclwbk = Nothing
Set xclsheet = Nothing
'xclapp.Quit
set xclapp = Nothing
此致 ScriptMan