By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Excel 2003 Application Question

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
http://www.wizkil-webs.net/NET/DotNe...m#_Toc78169306

hope this helps

"Jason" <so*****@microsoft.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2

P: n/a
It does help, thanks. However, I see that they are referencing the Excel
object model explicitly (i.e., they added a reference to their project or
solution via VisualStudio), whereas I am late-binding. I'm only doing this
because when I tried to add a reference I couldn't find Excel available as a
..Net reference (I added one called "office" but it doesn't seem to have any
available functions or properties). Any idea how I can get ahold of (and
register, I suppose) the reference?

"BrianDH" <No**********@nospam.com> wrote in message
news:da********************@telcove.net...
http://www.wizkil-webs.net/NET/DotNe...m#_Toc78169306

hope this helps

"Jason" <so*****@microsoft.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #3

P: n/a
OK
Under the COM Refference
I am using:
Microsoft Excel 9.0 Object Library - Excel.dll
Microsoft Office 9.0 Object Library - Office.dll
Imports system IO

B

"Jason" <so*****@microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
It does help, thanks. However, I see that they are referencing the Excel
object model explicitly (i.e., they added a reference to their project or
solution via VisualStudio), whereas I am late-binding. I'm only doing this
because when I tried to add a reference I couldn't find Excel available as a .Net reference (I added one called "office" but it doesn't seem to have any available functions or properties). Any idea how I can get ahold of (and
register, I suppose) the reference?

"BrianDH" <No**********@nospam.com> wrote in message
news:da********************@telcove.net...
http://www.wizkil-webs.net/NET/DotNe...m#_Toc78169306

hope this helps

"Jason" <so*****@microsoft.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
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



Nov 20 '05 #4

P: n/a
Not 100% on this, but I think you need the PIA for Excel 2003.

http://msdn.microsoft.com/library/de...assemblies.asp

Greg

"Jason" <so*****@microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
It does help, thanks. However, I see that they are referencing the Excel
object model explicitly (i.e., they added a reference to their project or
solution via VisualStudio), whereas I am late-binding. I'm only doing this
because when I tried to add a reference I couldn't find Excel available as a .Net reference (I added one called "office" but it doesn't seem to have any available functions or properties). Any idea how I can get ahold of (and
register, I suppose) the reference?

"BrianDH" <No**********@nospam.com> wrote in message
news:da********************@telcove.net...
http://www.wizkil-webs.net/NET/DotNe...m#_Toc78169306

hope this helps

"Jason" <so*****@microsoft.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
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



Nov 20 '05 #5

P: n/a
Hi
Use the following code to close the excel aplication

System.Runtime.InteropServices.Marshal.ReleaseComO bject
(xlApp)
xlapp = nothing

Kind Regards
Jorge
-----Original Message-----
I am having some trouble manipulating Excel files. Currently I amtrying to create and then close an Excel file/application with the followingcode. It works fine, except it leaves an EXCEL application open, which I cansee in the Task Manager. I have tried oExcel.Dispose(), but this generatesan error. How can I correct this code so that the object is properlydisposed 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
.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.