I am having an issue with Excel in a script. When the script finishes, Excel continues to exist as a running process if (and only if) I use a variable as the saveas file name. If I hard code the file name the process releases just fine (see comment under dim fileName_New line).
Not sure why it would matter but it's driving me CRAZY!!!
Any help is appreciated.
Rob
Script:
Dim fileName_New As String = Dts.Variables("fileName_new").Value.ToString
''''''''''''The above declaration causes Excel to continue to run
''''''''''''the below commented declaration works fine and 'Excel is released
'dim fileName_New as String = "e:\bby\test.xls" '
xlWorkBook_Dest.SaveAs(fileName_New)
''Choose new copy range so that the clipboard won't stop Excel from Closing
lrngCopyRange = wkshtSheet.Range("a1")
lrngCopyRange.Copy()
''Release xlWorkbooks
xlApp.Workbooks.Close()
''''''''''''''SHUT DOWN EXCEL'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
xlApp.Quit()
''Release xlWorkbook COM OBJECTS
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngRow)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngColumn)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngCopyRange)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wkshtSheet)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wkshtSheet2)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkBook_Dest)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
Dts.TaskResult = Dts.Results.Success
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp)
xlApp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
Not sure why it would matter but it's driving me CRAZY!!!
Any help is appreciated.
Rob
Script:
Dim fileName_New As String = Dts.Variables("fileName_new").Value.ToString
''''''''''''The above declaration causes Excel to continue to run
''''''''''''the below commented declaration works fine and 'Excel is released
'dim fileName_New as String = "e:\bby\test.xls" '
xlWorkBook_Dest.SaveAs(fileName_New)
''Choose new copy range so that the clipboard won't stop Excel from Closing
lrngCopyRange = wkshtSheet.Range("a1")
lrngCopyRange.Copy()
''Release xlWorkbooks
xlApp.Workbooks.Close()
''''''''''''''SHUT DOWN EXCEL'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
xlApp.Quit()
''Release xlWorkbook COM OBJECTS
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngRow)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngColumn)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lrngCopyRange)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wkshtSheet)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wkshtSheet2)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkBook_Dest)
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
Dts.TaskResult = Dts.Results.Success
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp)
xlApp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()