Close Excel Workbook

I’m trying to close an excel workbook. I have the name of the workbook stored in a string variable called “filenamestring” but I’m getting this error message.

I’ve tried setting the variable type as String and System.String

Thanks for your help.

Hi @Gavin_Mcmaster,

Check the variable type
It should be in Uipath.Excel.WorkbookApplication

Use Ctrl+K to create the variable always.
image

@varunk The problem is I need that variable as a Generic or String variable earlier in my workflow. How do I change the variable type later on in the workflow?

close workbook activity input is only accept workbook variable, not string.

try send your xaml

Hi @Gavin_Mcmaster

I think the way you did can work in VBA as you provided filename.

However in uipath if you want to close the excel workbook you have to provide an Excel Object which is created by UiPath. please find below image.

First step is to create a WB variable in Output you can see WB_Input variable which is of UiPath.Excel.WorkbookApplication. Second step Inside Close Workbook you can use this type of variable. Then it will work.

Hope this will solve your problem.

Regards,
Vijay.

@Vijay_Kumar_C Good suggestion. I tried it but it didn’t work.

My filename changes each day, so I’m storing it as a variable earlier in the workflow

if want to close workbook with different file names…,

i will just use element exist (edit selector) -> if element exist = true -> close window (edit the selector)

note:
edit selector =

  1. put * after the file name (“filename*”)
  2. and uncheck the unecessary selectors

the * = so you can recognize value of selector that always changed.

1 Like

Why use Close Workbook activity? The Excel file is not closing himself at the end of the Excel Application Scope activity ?

1 Like

In your image the Excel Application Scope is outputting a Workbook variable called ‘closefile’. You need to provide that variable in the close workbook activity.

Close workbook activity only accepts workbook variables. It is a bit confusing because in order to open a workbook, you provided the file path as a string earlier. However, once you have excel opened that is now it’s own new variable (an excel object) and is called a workbook variable

@Gavin_Mcmaster -
How do you know that it is not working ??
is that excel file still open on the screen ?? or
is it throwing any error message ??

before running this code can you please put kill process with “EXCEL” as input value and try it.

Regards,
Vijay.

@Gavin_Mcmaster

Just one suggestion. Why don’t you use Close Application activity with Selector as
" <wnd app=‘excel.exe’ title=‘Microsoft Excel - *’ />"

Can you give a try?