473,699 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with using Excel.Applicati on object

hi there,

i've got a form that populates a datagrid, and a button that calls a
function to export to an excel file.
All is well with the export, no errors are returned, but the Excel instance
doesnt want to terminate properly even when i set excelApp.Quit, and
excelApp = nothing.

has anyone else experienced a problem like this???
code below:
--------------------------------------------------------
Sub SaveToExcel(ByV al table As String, ByVal sql As String)

Try
Dim xlApp As New Excel.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQryTable As Excel.QueryTabl e
xlBook = xlApp.Workbooks .Add()
xlApp.DisplayAl erts = False
Do Until xlBook.Sheets.C ount = 1
xlBook.Sheets(1 ).Delete()
Loop

xlSheet = xlBook.ActiveSh eet
xlSheet.Name = "QueryBuild er Data"
xlQryTable = xlSheet.QueryTa bles.Add("OLEDB ;" & strConn,
xlSheet.Range(" A1"))
With xlQryTable
.Sql = sql
.Refresh()
End With

xlApp.DisplayAl erts = True
Dim strBookName As String = xlApp.GetSaveAs Filename(table,
fileFilter:="Ex cel Files (*.xls), *.xls")
If strBookName <> "False" Then xlBook.SaveAs(s trBookName)
xlSheet = Nothing
xlQryTable = Nothing
xlBook.Close(Fa lse)
xlBook = Nothing
xlApp.Quit()
xlApp = Nothing
Application.DoE vents()
Catch ex As Exception
MessageBox.Show ("An error occured while exporting to an Excel file.")
End Try

End Sub

--------------------------------------------------------
thanks,
Paul
Nov 20 '05 #1
4 2515
Hello Paul
I use a similar function and it quits normally.
Try the following :
System.Runtime. InteropServices .Marshal.Releas eComObject
(objExcelApp)

Kind Regards
Jorge
-----Original Message-----
hi there,

i've got a form that populates a datagrid, and a button that calls afunction to export to an excel file.
All is well with the export, no errors are returned, but the Excel instancedoesnt want to terminate properly even when i set excelApp.Quit, andexcelApp = nothing.

has anyone else experienced a problem like this???
code below:
--------------------------------------------------------
Sub SaveToExcel(ByV al table As String, ByVal sql As String)
Try
Dim xlApp As New Excel.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQryTable As Excel.QueryTabl e
xlBook = xlApp.Workbooks .Add()
xlApp.DisplayA lerts = False
Do Until xlBook.Sheets.C ount = 1
xlBook.Sheets(1 ).Delete()
Loop

xlSheet = xlBook.ActiveSh eet
xlSheet.Name = "QueryBuild er Data"
xlQryTable = xlSheet.QueryTa bles.Add("OLEDB ;" & strConn,
xlSheet.Range( "A1"))
With xlQryTable
.Sql = sql
.Refresh()
End With

xlApp.DisplayA lerts = True
Dim strBookName As String = xlApp.GetSaveAs Filename (table,fileFilter:="E xcel Files (*.xls), *.xls")
If strBookName <> "False" Then xlBook.SaveAs(s trBookName)
xlSheet = Nothing
xlQryTable = Nothing
xlBook.Close(F alse)
xlBook = Nothing
xlApp.Quit()
xlApp = Nothing
Application.Do Events()
Catch ex As Exception
MessageBox.Show ("An error occured while exporting to an Excel file.")End Try

End Sub

--------------------------------------------------------
thanks,
Paul
.

Nov 20 '05 #2
Jorge,

i added the extra line you mentioned, but still doesnt unload it.
After line by line elimination, i have found the problem to be when i load
the following:

xlBook = xlApp.Workbooks .Add()

although i unload this object before i unload the Excel object, it still
doesnt solve my problem..
Also, i added the ReleaseComObjec t on this object , but still no luck.

Any ideas?
thanks,
Paul.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ******@phx.gbl. ..
Hello Paul
I use a similar function and it quits normally.
Try the following :
System.Runtime. InteropServices .Marshal.Releas eComObject
(objExcelApp)

Kind Regards
Jorge
-----Original Message-----
hi there,

i've got a form that populates a datagrid, and a button

that calls a
function to export to an excel file.
All is well with the export, no errors are returned, but

the Excel instance
doesnt want to terminate properly even when i set

excelApp.Quit, and
excelApp = nothing.

has anyone else experienced a problem like this???
code below:
--------------------------------------------------------
Sub SaveToExcel(ByV al table As String, ByVal sql As

String)

Try
Dim xlApp As New Excel.Applicati on
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQryTable As Excel.QueryTabl e
xlBook = xlApp.Workbooks .Add()
xlApp.DisplayA lerts = False
Do Until xlBook.Sheets.C ount = 1
xlBook.Sheets(1 ).Delete()
Loop

xlSheet = xlBook.ActiveSh eet
xlSheet.Name = "QueryBuild er Data"
xlQryTable = xlSheet.QueryTa bles.Add("OLEDB ;" & strConn,
xlSheet.Range( "A1"))
With xlQryTable
.Sql = sql
.Refresh()
End With

xlApp.DisplayA lerts = True
Dim strBookName As String = xlApp.GetSaveAs Filename

(table,
fileFilter:="E xcel Files (*.xls), *.xls")
If strBookName <> "False" Then xlBook.SaveAs(s trBookName)
xlSheet = Nothing
xlQryTable = Nothing
xlBook.Close(F alse)
xlBook = Nothing
xlApp.Quit()
xlApp = Nothing
Application.Do Events()
Catch ex As Exception
MessageBox.Show ("An error occured while exporting to an

Excel file.")
End Try

End Sub

--------------------------------------------------------
thanks,
Paul
.

Nov 20 '05 #3
Paul,
This is how i declare them:
Dim objExcelApp As New Excel.Applicati on
Dim objBook As Excel.Workbook = objExcelApp.Wor kbooks.Add
Dim objSheet As Excel.Worksheet = DirectCast
(objExcelApp.Ac tiveSheet, Excel.Worksheet )

This is how i terminate them:
objBook.Close()
objSheet = Nothing
objExcelApp.Qui t()
System.Runtime. InteropServices .Marshal.Releas eComObject
(objExcelApp)
objExcelApp = Nothing
GC.Collect()

Kind Regards
Jorge
-----Original Message-----
Jorge,

i added the extra line you mentioned, but still doesnt unload it.After line by line elimination, i have found the problem to be when i loadthe following:

xlBook = xlApp.Workbooks .Add()

although i unload this object before i unload the Excel object, it stilldoesnt solve my problem..
Also, i added the ReleaseComObjec t on this object , but still no luck.
Any ideas?
thanks,
Paul.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in messagenews:13******* *************** *******@phx.gbl ...
Hello Paul
I use a similar function and it quits normally.
Try the following :
System.Runtime. InteropServices .Marshal.Releas eComObject (objExcelApp)

Kind Regards
Jorge
>-----Original Message-----
>hi there,
>
>i've got a form that populates a datagrid, and a button
that calls a
>function to export to an excel file.
>All is well with the export, no errors are returned,
but the Excel instance
>doesnt want to terminate properly even when i set

excelApp.Quit, and
>excelApp = nothing.
>
>has anyone else experienced a problem like this???
>code below:
>------------------------------------------------------
-- >Sub SaveToExcel(ByV al table As String, ByVal sql As

String)
>
>Try
>Dim xlApp As New Excel.Applicati on
>Dim xlBook As Excel.Workbook
>Dim xlSheet As Excel.Worksheet
>Dim xlQryTable As Excel.QueryTabl e
>xlBook = xlApp.Workbooks .Add()
>xlApp.DisplayA lerts = False
>Do Until xlBook.Sheets.C ount = 1
> xlBook.Sheets(1 ).Delete()
>Loop
>
>xlSheet = xlBook.ActiveSh eet
>xlSheet.Name = "QueryBuild er Data"
>xlQryTable = xlSheet.QueryTa bles.Add("OLEDB ;" & strConn, >xlSheet.Range( "A1"))
>With xlQryTable
> .Sql = sql
> .Refresh()
>End With
>
>xlApp.DisplayA lerts = True
>Dim strBookName As String = xlApp.GetSaveAs Filename

(table,
>fileFilter:="E xcel Files (*.xls), *.xls")
>If strBookName <> "False" Then xlBook.SaveAs (strBookName) >xlSheet = Nothing
>xlQryTable = Nothing
>xlBook.Close(F alse)
>xlBook = Nothing
>xlApp.Quit()
>xlApp = Nothing
>Application.Do Events()
>Catch ex As Exception
> MessageBox.Show ("An error occured while exporting to an Excel file.")
>End Try
>
>End Sub
>
>------------------------------------------------------

-- >thanks,
>Paul
>
>
>.
>

.

Nov 20 '05 #4
thanks jorge,

i used your example and it works fine - although i have no idea what was the
problem with my example:))

Paul.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ******@phx.gbl. ..
Paul,
This is how i declare them:
Dim objExcelApp As New Excel.Applicati on
Dim objBook As Excel.Workbook = objExcelApp.Wor kbooks.Add
Dim objSheet As Excel.Worksheet = DirectCast
(objExcelApp.Ac tiveSheet, Excel.Worksheet )

This is how i terminate them:
objBook.Close()
objSheet = Nothing
objExcelApp.Qui t()
System.Runtime. InteropServices .Marshal.Releas eComObject
(objExcelApp)
objExcelApp = Nothing
GC.Collect()

Kind Regards
Jorge
-----Original Message-----
Jorge,

i added the extra line you mentioned, but still doesnt

unload it.
After line by line elimination, i have found the problem

to be when i load
the following:

xlBook = xlApp.Workbooks .Add()

although i unload this object before i unload the Excel

object, it still
doesnt solve my problem..
Also, i added the ReleaseComObjec t on this object , but

still no luck.

Any ideas?
thanks,
Paul.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in

message
news:13******* *************** *******@phx.gbl ...
Hello Paul
I use a similar function and it quits normally.
Try the following :
System.Runtime. InteropServices .Marshal.Releas eComObject (objExcelApp)

Kind Regards
Jorge
>-----Original Message-----
>hi there,
>
>i've got a form that populates a datagrid, and a button that calls a
>function to export to an excel file.
>All is well with the export, no errors are returned, but the Excel instance
>doesnt want to terminate properly even when i set
excelApp.Quit, and
>excelApp = nothing.
>
>has anyone else experienced a problem like this???
>code below:
>------------------------------------------------------ -- >Sub SaveToExcel(ByV al table As String, ByVal sql As
String)
>
>Try
>Dim xlApp As New Excel.Applicati on
>Dim xlBook As Excel.Workbook
>Dim xlSheet As Excel.Worksheet
>Dim xlQryTable As Excel.QueryTabl e
>xlBook = xlApp.Workbooks .Add()
>xlApp.DisplayA lerts = False
>Do Until xlBook.Sheets.C ount = 1
> xlBook.Sheets(1 ).Delete()
>Loop
>
>xlSheet = xlBook.ActiveSh eet
>xlSheet.Name = "QueryBuild er Data"
>xlQryTable = xlSheet.QueryTa bles.Add("OLEDB ;" & strConn, >xlSheet.Range( "A1"))
>With xlQryTable
> .Sql = sql
> .Refresh()
>End With
>
>xlApp.DisplayA lerts = True
>Dim strBookName As String = xlApp.GetSaveAs Filename
(table,
>fileFilter:="E xcel Files (*.xls), *.xls")
>If strBookName <> "False" Then xlBook.SaveAs (strBookName) >xlSheet = Nothing
>xlQryTable = Nothing
>xlBook.Close(F alse)
>xlBook = Nothing
>xlApp.Quit()
>xlApp = Nothing
>Application.Do Events()
>Catch ex As Exception
> MessageBox.Show ("An error occured while exporting to an Excel file.")
>End Try
>
>End Sub
>
>------------------------------------------------------ -- >thanks,
>Paul
>
>
>.
>

.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3366
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
2
5433
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
14
5793
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
0
1764
by: Adrian Belen via .NET 247 | last post by:
hi, I have a problem when I try to open an excel document in a AxWebBrowser Component in VB.NET. The problem appear in this situation: Before to all the Excel application is opened from the user with some document xls. After that my application open an excel document (can be another document) using the component AxWebBrowser Then the first applications have problem when I try to modify the document.
4
1842
by: Ivan | last post by:
Hi All, I have tried to automate excel in vb.net and i found a problem that i can't find the solution in anywhere... i hope someone can help me in this group.... the problem is i try using the excel function -- 'Excel.Workbooks.Open("C:\Filename.xls")' it pops up an error msg -- 'object reference not set to an instance of an object'
4
3123
by: goonsquad | last post by:
I'm writing an Excel Automation app and I'm running to a problem early on with what should be a basic step. Dim oExcel As Object Dim oBook As Object Dim oSheet As Object Dim oRng As Excel.Range oExcel = CreateObject("Excel.Application") oBook = oExcel.Workbooks.Add oSheet = oBook.Worksheets(1)
5
8948
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
6
2292
by: Darrell Wesley | last post by:
A VB2003 application upgraded to VB2005 that builds an Excel spreadsheet. Everything appears to work correctly except that the Excel object does not go away it is still in the Process list in task manager. This problem did not exist in the VB2003 version. Are there a any ideas of what might be happening? All of the Excel objects are being disposed of by setting them to Nothing and the Quit method is called for Excel. I've even used...
0
4128
by: Bill Fallon | last post by:
I am developing a VB.Net application with VS 2005 that opens an Excel workbook and populates the worksheet with data. I started developing the application with Office 2007 installed on my Vista OS, but after I discovered that it won't run on a system with Office 2003, I uninstalled Office 2007 and installed Office 2003. I reset the reference in .Net to the Microsoft Excel 11.0 Object Library. The application works fine from the ..Net...
0
8618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8916
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.