kill a process by code?

T

touf

Hi,
I use the folowing code to create a new Excel file using a query
It creates an excel file and save it on the disc, but When I double-clic on
it (explorer) it open Excel and bloc,(don't display the data), it does the
same with all excel files.

I've found that it creates a process called Excel, when I end it (Windows
Task Manager) the problem is resolved.

I think that I need somewhere to kill the process..(I use oExcel.Quit() but
doesn't do the job)

Any help please.



Dim oExcel As Object

Dim oBook As Object

Dim oSheet As Object

oExcel = CreateObject("Excel.Application")

oBook = oExcel.Workbooks.Add

oSheet = oBook.Worksheets(1)

.....

.... code......

.....

oBook.SaveAs(fileName)

oQryTable = Nothing

oSheet = Nothing

oBook = Nothing

oExcel.Quit()

oExcel = Nothing



It creates an excel file and save it on the disc, but When I double-clic on
it (explorer) it open Excel and bloc,(don't display the data), it does the
same with all excel files.

I've found that it create a process called Excel, when I end it the problem
is resolved.
 
H

Herfried K. Wagner [MVP]

* "touf said:
It creates an excel file and save it on the disc, but When I double-clic on
it (explorer) it open Excel and bloc,(don't display the data), it does the
same with all excel files.

I've found that it creates a process called Excel, when I end it (Windows
Task Manager) the problem is resolved.

I think that I need somewhere to kill the process..(I use oExcel.Quit() but
doesn't do the job)

Close all workbooks, then use:

\\\
objExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel)
objExcel = Nothing
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
T

touf

Thanks Herfried, but it doesn't resolve the problem
here is the whole code, can you please take a look to see what is wrong
Thanks.

Dim oExcel As Object

Dim oBook As Excel.Workbook

Dim oSheet As Object

oExcel = CreateObject("Excel.Application")

oBook = oExcel.Workbooks.Add

oSheet = oBook.Worksheets(1)

'Create the QueryTable object.

Dim oQryTable As Object

oQryTable = oSheet.QueryTables.Add(conString, oSheet.Range("A1"), sqlstring)

oQryTable.RefreshStyle = 2 ' xlInsertEntireRows = 2

oQryTable.Refresh(False)

'Save the workbook and quit Excel.

If Dir(fileName) <> "" Then Kill(fileName)

oBook.SaveAs(fileName)

oQryTable = Nothing

oSheet = Nothing

oBook.Close()

oBook = Nothing

oExcel.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)

oExcel = Nothing


Herfried K. Wagner said:
HOWTO: Automate Microsoft Excel from Visual Basic .NET
<http://support.microsoft.com/default.aspx?scid=kb;en-us;301982>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top