charlieb01
asked on
VB.NET 2010 and MS Excel
I have a VB.NET 2010 app that creates a new test report based on a template XLSX file. When I run my program and get back to my main form, if I go to the Task Manager I can see that Excel.exe process is still running. If I exit my program then the Excel process disappears from the task manager.
I have shown my code below. Is there some other command I am missing that will stop the Excel process?
Thanks,
Charlie
CODE:
Public Sub CreateReportA()
If appExcel Is Nothing Then
appExcel = New Excel.Application
End If
appExcel.Visible = False
Dim myPath As String = Application.StartupPath
Dim mynewfilename As String
Dim myDate = Format(Now, "yyyy_MM_dd_hh_mm_ss")
mynewfilename = myPath & "\" & "TestReports\" & rpt_Serial_Number_A & "_" & myDate & ".xlsx"
reportFileNameSysA = mynewfilename
oWB = appExcel.Workbooks.Open(my Path & "\" & "TestReportFinal.xlsx", True, True)
oSheet = oWB.Sheets(1)
oSheet.Range("rpt_Serial_N umber").Va lue = rpt_Serial_Number_A
oSheet.Range("rpt_Part_Num ber").Valu e = rpt_Part_Number_A
oSheet.Range("rpt_ATP_Vers ion").Valu e = rpt_ATP_Version_A
oSheet.Range("rpt_Internal _Order").V alue = rpt_Internal_Order_A
oSheet.Range("rpt_Technici an").Value = rpt_Technician_A
oSheet.Range("rpt_Test_Dat e").Value = rpt_Test_Date_A
oWB.SaveAs(mynewfilename)
oSheet = Nothing
oWB.Close()
oWB = Nothing
appExcel.Quit()
appExcel = Nothing
End Sub
I have shown my code below. Is there some other command I am missing that will stop the Excel process?
Thanks,
Charlie
CODE:
Public Sub CreateReportA()
If appExcel Is Nothing Then
appExcel = New Excel.Application
End If
appExcel.Visible = False
Dim myPath As String = Application.StartupPath
Dim mynewfilename As String
Dim myDate = Format(Now, "yyyy_MM_dd_hh_mm_ss")
mynewfilename = myPath & "\" & "TestReports\" & rpt_Serial_Number_A & "_" & myDate & ".xlsx"
reportFileNameSysA = mynewfilename
oWB = appExcel.Workbooks.Open(my
oSheet = oWB.Sheets(1)
oSheet.Range("rpt_Serial_N
oSheet.Range("rpt_Part_Num
oSheet.Range("rpt_ATP_Vers
oSheet.Range("rpt_Internal
oSheet.Range("rpt_Technici
oSheet.Range("rpt_Test_Dat
oWB.SaveAs(mynewfilename)
oSheet = Nothing
oWB.Close()
oWB = Nothing
appExcel.Quit()
appExcel = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Fernando,
I tried your suggestion but the Excel process is still running (as seen in Task Manager) and does not stop until I end my program. Any other ideas? I am really stumped by this.
Thanks in advance
Matti:
By creating the variable 'myDate' formatted as I did in my program and then appending that to the end of the new filename, I am assured that the new spreadsheet filename will be unique. It also allows my user to see when the test was run simply by looking at the entire filename.
I tried your suggestion but the Excel process is still running (as seen in Task Manager) and does not stop until I end my program. Any other ideas? I am really stumped by this.
Thanks in advance
Matti:
By creating the variable 'myDate' formatted as I did in my program and then appending that to the end of the new filename, I am assured that the new spreadsheet filename will be unique. It also allows my user to see when the test was run simply by looking at the entire filename.
If you have any other com objects associated with the Excel object they too need to be released. Com objects will not end until all the objects reference counts goes to zero.
Well I think there is no 64bit solution Win32 API would have but this is a VBA/64bit app issue, so that you run someting interopp that's 32 bit port to 64 bit code. As you run this in Visual Studio try 32bit compilation, so the compile options from VS.
ASKER
Fernando,
Do you know of anyway I can determine com objects that are running?
Do you know of anyway I can determine com objects that are running?
Sorry but I do not.
Now is for Date and Time is for specific timing Format returns a String in defined format
Matti