on 09-19-2022 11:05 AM
Hi all,
I have an automation, where I create and open some number of Excel workbooks. I don't know, how many there will be. It depends on specific parameters. But I know the maximum number of them.
I want to close all opened workbooks at the end of automation. But I don't know how. Any ideas?
Or if there is a tool that tells me whether a specific workbook is opened - that would be also helpful.
Or is there an option to close specific Excel?
P.S. I use Cloud Studio and attended mode.
Regards
Lucie
Dear Lucie,
The usual solution is to keep the Excel file open only while working with it. But in my case I am not sure if there is some file open before I start working with excel in iRPA. Below I am attaching the script I use to close all Excel instances. Credit belongs to Mohamed:
function formatEscapCaracters(f) {
return f.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
}
irpa_core.core.log('custom script close any opened Excel', irpa_core.enums.logType.Info, 'excelAutomation');
try {
var MSScrCtrl = irpa_core.activeX.create("MSScriptControl.ScriptControl");
MSScrCtrl.AllowUI = 1;
MSScrCtrl.Language = 'VBScript';
var VBScode = formatEscapCaracters(function () {/*!
Sub closeAnyOpenedExcel()
For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = 'EXCEL.EXE'")
Process.Terminate
Next
End Sub
*/});
MSScrCtrl.AddCode(VBScode);
MSScrCtrl.Run("closeAnyOpenedExcel");
irpa_core.core.log('custom script close any opened Excel', irpa_core.enums.logType.Info, 'excelAutomation');
} catch (error) {
irpa_core.core.log('closeAnyOpenedExcel Exception occured:' + error, irpa_core.enums.logType.Error, 'excelAutomation');
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.