How to close excel process {The process cannot access the file because it is being used by another process.}

Hello, I need to parse an excel file using vba/vb.net script and return collection of elements (key/value).
When I am using vba - I can’t cast com object (returned collection) to something that I can read. But it nice to close process when work is done (just add close workbook activity to final block).
Vb.Net - Ok, I get correct collection, but can’t correctly close process and get this error when trying to move file.“The process cannot access the file because it is being used by another process”
I even try to invoke code to kill all excel process before moving file and sometime I get this error.

Please help.
I prefer Vb.net (so, i need to know how to cast comObject)

@yaniketz

Please try this code if it is possible.

Check the file path is exists or not before close the file.

Or

create a variable for garbage collection and try this code

GC.Collect()

if it is not help to resolve. Please share more details with your code.

Thanks,
Pradeep Sridharan

1 Like

@yaniketz Use kill process to kill all excel file using vbscript refer here is a xaml

1 Like

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