Question about Close Workbook activity

In my workflow im using Write Range to update table in Excel. Then i try to save changes by using Close Workbook activity with the parameters:
Save Changes: True
FIlename: [the same variable that used in the Write Range].
Workbook: empty.

But instead of automatically saving and closing Excel file, Excel application provide pop up windows with the question: “A file named * already exists in the location. Do you want to replace it?”

Is it possible somehow to override that?

Set a variable for the workbooksession from your writerange, and pass that to the CloseWorkbook activity (no filename needed). It will then use the same excel “session” to the file.
At least that’s what works for me.

yes.
the scenario with session variable also worked for me. but when i reuse the same variable for editing next file: in the Write Range and Close Workbook activities, i have got an error # The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). in total i have to update 6 files in one workflow.
maybe there is some working scenario without creation 6 different session variables - one for each file?
and path variable for the files already present in the workflow, that is why im interested in reusing them.

Try setting it to null (Nothing) between the files.
The excel activities check if the session object has something, and if it does, they try to connect to that session.

That said, be careful with reusing variables, it can get confusing. So even if sometimes having multiple variables can luck meh at first, it avoids value leakage between different things.

Also, you may want to look into variable scopes, which is a way of limiting the variable lifetime within a workflow.

how can i set the variable to null (Nothing)? what is the correct syntax for the assign activity?

In assign:

yourVariableName = Nothing

That’s really it :slight_smile:

2 Likes

Huuuraaaaayyyy!
That’s worked! Thanks for the support.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.