Hi All
I am having trouble with an Excel file The Excel file is in use by another program.
How to check if excel file is open before excel activity and then close.
Hi All
I am having trouble with an Excel file The Excel file is in use by another program.
How to check if excel file is open before excel activity and then close.
Welcome to forums
You can place Kill process activity and type as Excel before the Excel application Scope
It will confirms that it kill the Excel Instance and open without any issue
Hope this may help you
Thanks,
Srini
Hi @shan.huang
It is impossible to check the excel file is open or nor.
Before using excel activities you can kill the opened excel by using “Kill Process”. It will close the process automatically. Find out the below image, In Process Name option give the “EXCEL.EXE”.
Regards, It may help for your automation!
Hi @shan.huang ,
Welcome to UiPath Community!
You can try using the Get Processes activity to get all the running processes in the machine.
Loop through all the processes and search if excel is there.
If it is found then kill it.
Else just use Kill process, pass excel in params.
Additional Question: aren’t you using Excel Application Scope to work on Excel file? Try using that if haven’t used already.
Hope this helps!
Thanks,
Aditya
Hi @shan.huang
Use “Kill Process” Activity
Hi @shan.huang
We should kill all the applications before starting the automation, in this case you should use a kill process activity, pass the process name like this
Regards!
I try to do this process. The output datatype of get process activity is Collections. I try to iterate in for each loop and give a if condition like “EachProcess.contains(EXCEL.EXE)”. In the else block I have given a kill process. It doesn’t can you please eloberate for more information.
Regards.
Hi @shan.huang
First, add the “Excel Application Scope” activity to your UiPath workflow and add a “Try Catch” activity.
Within the “Try” block, add the Excel activities you want to perform, such as reading or writing data. In the “Catch” block, add a “System.Exception” type handler. This will capture any exception thrown during the Excel activities.Inside the “Catch” block, add the following activities to check if the Excel file is open and close it if necessary:
a. Use the “Assign” activity to create a Boolean variable, let’s call it “isExcelOpen,” and assign it the value of False.
b. Add an “Excel Application Scope” activity within the “Catch” block.
c. In the properties of the new “Excel Application Scope” activity, specify the same Excel file you were working with in the “Try” block.
d. Within this nested “Excel Application Scope,” add an “Assign” activity to update the value of the “isExcelOpen” variable. Use the following expression:
isExcelOpen = True
e. Finally, add an “If” activity after the nested “Excel Application Scope” to check the value of “isExcelOpen.” If it is True, it means the Excel file was open, and you can add a “Close Workbook” activity to close the file.
Thanks!!
Hi Srini
I don’t know which process opened the Excel or I forgot to close the Excel when I started it.
Is there any activity that can check if Excel is open, or can close Excel directly.
Regards
mark it as solution if you are good with it
Hi @shan.huang
Enable the classic activities. as shown in screenshot below. You would be able to find the close workbook activity there
Thank adiijaiin
I can use close workbook activity.
Let us know if your automation works.
Happy Automation.
Hi @Nitya1
Thank you for the solution, Already added the method to my automation works as an exception exclusion.
Currently the automation works fine.
Thanks
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.