Excel file in use

Excel file is still open in runtime and any command that use the same file will get this error.

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

Error : 

The process cannot access the file because it is being used by another process.
Excel file is still open in runtime and any command that use the same file will get this error.

Solution :

Add a script task with the code below.

Public Sub Main()
        Dim procList() As Process = Process.GetProcesses()
        Dim k As Integer
        For k = 0 To procList.GetUpperBound(0) Step k + 1
            If procList(k).ProcessName = "EXCEL" Then
                procList(k).Close()
                procList(k).Dispose()
            End If
        Next
        GC.Collect()
        GC.WaitForPendingFinalizers()
        Dts.TaskResult = ScriptResults.Success
    End Sub