How to close specific excel files in uipath without killing all excel instances?

Hi all ,
I am facing an issue with excel files that i am using in my process. BOT is using an input excel file and writing the output in same excel . In my process i am using excel application scope different sequences. After completing the process i need to close that specific workbook. If i kill all instance it will effect the end users all other excel files.
I have named an output variable for workbook (1st excel applcation scope).
But i am unable to use that variable to further application scopes (USE Existing workbook property),It throws a error(the following overload groups are configured uipath existing workbook).attaching SS below !

.
Is there any way to close excel without interepting with end users excel files.

@ramees.pk,

You can use Close WorkBook activity with in the excel application scope.

Else you can try with Close Applciation, this will work with correct titles, so you need to pass the title of the excel you need to close.

<wnd app='excel.exe' cls='XLMAIN' title='Book1 - Excel' />
3 Likes

Thanks for reply,
So where ever i am using excel application scope i need to use close workbook within that scope right?
there is an another property like use existing workbook, can i give workbook variable over there? Does it works?

Hi friend ,have u solved your problem ,I just met the same problem ,wanna kill specific excel without kill all excel process.

There are multiple ways for dealing with the running instance of excel. mentioning the few here.

  1. You can use “close workbook activity” if you have opened the excel instance of a particular file using excel application scope. It also works with already open files but sometimes it fails.

  2. Use the “Close Application” activity, where you can give the selector according to your file identifier. (mostly it is the filename). This activity can be used to close temp files too if you have the file name.

  3. you can get running instances using the System.Runtime.InteropServices.Marshal.GetActiveObject(“Application.Excel”)
    and loop through them to identify the workbook you need, then you can do multiple operations including closing the workbook.
    P.S. 3rd option is a better approach while making custom activity and should be used up to .Net Framework 4, as it is not directly supported in .Net core(You can write the code by creating a new class though).

Hope this helps,
Cheers!

Can you give us a clear instruction on how to use the 3rd option? Thank you.