I'm struggling to find a solution for this funky behavior for the COM logic within Visual Studio. I have already reduced the 2DOT notation into smaller parts... nothing seems to work. There is always a remnant of excel in the memory.
Even In this link i had no success. Any guidance or help here would be mostly appreciated. I have no idea on what else to do or try...
Here is my code:
Private Sub FrmListTables_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim XL As Object : XL = New Excel.Application
Dim WBS As Workbooks = XL.Workbooks
Dim WB As Workbook = WBS.Open(WorkbookPath)
LstSheets.Items.Clear
For Each Sheet As Worksheet In WB.Worksheets
LstSheets.Items.Add(Sheet.Name)
Next
WB.Close(False)
WBS.Close()
XL.Quit()
ReleaseComObject(WB)
ReleaseComObject(WBS)
ReleaseComObject(XL)
WB = Nothing
WBS = Nothing
XL = Nothing
End Sub
Private Sub ReleaseComObject(ByRef obj As Object)
Try
Do Until Runtime.InteropServices.Marshal.ReleaseComObject(obj) <= 0
Loop
Catch
Finally
obj = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Sub