handling excel worksheets.
-
hi all, i am using an excel file in vb.net as following Dim AppExcl As Excel.Application AppExcl = New Excel.Application If AppExcl Is Nothing Then MsgBox("Invalid Action: Excel Could not be Started!", MsgBoxStyle.Critical, "Sys Error") Environment.ExitCode = 0 Exit Sub End If AppExcl.Workbooks.Open("path\filename.xls) With AppExcl '.Visible = False .Range("N7").Value = VATNO.Trim .Range("E7").Value = Format(xVAT_DtF.Date, "dd/MM/yyyy") .Range("H7").Value = Format(xVAT_DtT.Date, "dd/MM/yyyy") .Range("D9").Value = CoName.Trim .Range("H9").Value = CoStatus.Trim .Range("M9").Value = xCoType.Trim End With With AppExcl Dim xPth As String = xChkxOrxCreateDir() If Len(xPth.Trim) = 0 Then Exit Sub .ActiveWorkbook.SaveAs(xPth & "\Abc3.XLSX", , , , , ,XlSaveAsAccessMode.xlNoChange) .Visible = True .DisplayAlerts = False .Workbooks.Close() .Quit() End With it is working very fine, but when i shutdown my system i found a number of excel files(as many times i use this excel file) opened about which system ask to save or not these files. kindly help me. thanks
rmshah Developer
-
hi all, i am using an excel file in vb.net as following Dim AppExcl As Excel.Application AppExcl = New Excel.Application If AppExcl Is Nothing Then MsgBox("Invalid Action: Excel Could not be Started!", MsgBoxStyle.Critical, "Sys Error") Environment.ExitCode = 0 Exit Sub End If AppExcl.Workbooks.Open("path\filename.xls) With AppExcl '.Visible = False .Range("N7").Value = VATNO.Trim .Range("E7").Value = Format(xVAT_DtF.Date, "dd/MM/yyyy") .Range("H7").Value = Format(xVAT_DtT.Date, "dd/MM/yyyy") .Range("D9").Value = CoName.Trim .Range("H9").Value = CoStatus.Trim .Range("M9").Value = xCoType.Trim End With With AppExcl Dim xPth As String = xChkxOrxCreateDir() If Len(xPth.Trim) = 0 Then Exit Sub .ActiveWorkbook.SaveAs(xPth & "\Abc3.XLSX", , , , , ,XlSaveAsAccessMode.xlNoChange) .Visible = True .DisplayAlerts = False .Workbooks.Close() .Quit() End With it is working very fine, but when i shutdown my system i found a number of excel files(as many times i use this excel file) opened about which system ask to save or not these files. kindly help me. thanks
rmshah Developer
Are your COM objects being cleaned up properly? You need to use
Marshal.ReleaseComObject
to release all of the resources that are allocated when using the Excel interop classes. See this[^] thread for details (code is in C# but same principal applies).r_mohd wrote:
it is working very fine, but
Thanks, it always makes me chuckle when people say "It works fine but . . .". If there's a but then it isn't working fine, is it? :-D
:badger: