ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB.Net: Create Excel File/App? (https://www.excelbanter.com/excel-programming/305060-vbulletin-net-create-excel-file-app.html)

Jason[_34_]

VB.Net: Create Excel File/App?
 
I am having some trouble manipulating Excel files. Currently I am
trying to create and then close an Excel file/application with the following
code. It works fine, except it leaves an EXCEL application open, which I can
see in the Task Manager. I have tried oExcel.Dispose(), but this generates
an error. How can I correct this code so that the object is properly
disposed of? Thanks!

Public Sub CreateExcelFile(Optional ByVal sFileName As String =
"")
If Len(sFileName) 0 Then FileName = sFileName
If Not Len(FileName) 0 Then
MsgBox("The 'FileName' property must be set before the
'CreateExcelFile' method may be utilized", , "ERROR")
Exit Sub
End If
oExcel = CreateObject("Excel.Application")
With oExcel
.SheetsInNewWorkbook = 1
oExcel = .Workbooks.Add
.Save(FileName)
.Quit()
End With
oExcel = Nothing
End Sub



Michael Tomasura[_2_]

VB.Net: Create Excel File/App?
 
Look at this

Office Application Does Not Quit After Automation from Visual Studio .NET
Client
http://support.microsoft.com/default...B;en-us;317109

Michael Tomasura
"Jason" wrote in message
...
I am having some trouble manipulating Excel files. Currently I am
trying to create and then close an Excel file/application with the

following
code. It works fine, except it leaves an EXCEL application open, which I

can
see in the Task Manager. I have tried oExcel.Dispose(), but this generates
an error. How can I correct this code so that the object is properly
disposed of? Thanks!

Public Sub CreateExcelFile(Optional ByVal sFileName As String =
"")
If Len(sFileName) 0 Then FileName = sFileName
If Not Len(FileName) 0 Then
MsgBox("The 'FileName' property must be set before the
'CreateExcelFile' method may be utilized", , "ERROR")
Exit Sub
End If
oExcel = CreateObject("Excel.Application")
With oExcel
.SheetsInNewWorkbook = 1
oExcel = .Workbooks.Add
.Save(FileName)
.Quit()
End With
oExcel = Nothing
End Sub





Jason[_34_]

VB.Net: Create Excel File/App?
 
Perfect! Thanks.

"Michael Tomasura" wrote in message
...
Look at this

Office Application Does Not Quit After Automation from Visual Studio .NET
Client
http://support.microsoft.com/default...B;en-us;317109

Michael Tomasura
"Jason" wrote in message
...
I am having some trouble manipulating Excel files. Currently I am
trying to create and then close an Excel file/application with the

following
code. It works fine, except it leaves an EXCEL application open, which I

can
see in the Task Manager. I have tried oExcel.Dispose(), but this

generates
an error. How can I correct this code so that the object is properly
disposed of? Thanks!

Public Sub CreateExcelFile(Optional ByVal sFileName As String

=
"")
If Len(sFileName) 0 Then FileName = sFileName
If Not Len(FileName) 0 Then
MsgBox("The 'FileName' property must be set before the
'CreateExcelFile' method may be utilized", , "ERROR")
Exit Sub
End If
oExcel = CreateObject("Excel.Application")
With oExcel
.SheetsInNewWorkbook = 1
oExcel = .Workbooks.Add
.Save(FileName)
.Quit()
End With
oExcel = Nothing
End Sub








All times are GMT +1. The time now is 12:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com