Can somebody help with this script I am using for closing/terminating SAP Workbook? This worked for a long time until the time that the company updated our MS Office to a new version (MS Office 365 ProPlus). The intention of this code is to force close a certain SAP generated spreadsheets that keeps on auto-pop up when extracting a SAP reports. This old code was shared by @ScriptMan before in this forum.
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
Based on my initial checking, the issue is found in this part as it keeps on looping endlessly (detected it by putting a MsgBox after the loop). I have noticed that the new version of Excel 2016 makes the generated spreadsheets as new instance/session like it keeps on creating new Excel.exe in the process tab.
do
err.clear
Set xclwbk = xclApp.Workbooks.Item(SAP_Workbook)
If Err.Number = 0 Then exit do
wscript.sleep 2000
loop