Closing Excel From VB

N

Nitin

Hi guys
I am having problem in closing the excel application from my COM Component
I have following code in one of my COM method and when the method finishes, I still see Excel application running in task ba

can anyone help me? please can you tell me what i am doing wrong? Thanks in advanc

Dim appXl As Excel.Applicatio
Dim oWorkBook As Excel.Workboo
Dim qTable As Excel.QueryTabl

Set appXl = CreateObject("Excel.Application"
appXl.Workbooks.Open "someifle.xls

'' import the text fil
Set qTable = appXl.ActiveSheet.QueryTables.Add(Connection:=
"TEXT;" & strCSVFileName, Destination:=Range("A1")

For Each oWorkBook In appXl.Workbook
oWorkBook.Close SaveChanges:=Tru
oWorkBook.Application.Qui
Nex

Set qTable = Nothin
appXl.Qui
Set oWorkBook = Nothin
Set appXl = Nothing
 
N

Nitin

Sorry Guys
the following statment is not there i just added to varify it works or not It doesnt work

oWorkBook.Application.Qui
 
N

Nitin Patil

Hi
I tried it but didn work
here is the new code

Dim appXl As Excel.Application
Dim oWorkBook As Excel.Workbook
Dim qTable As Excel.QueryTable

Set appXl = CreateObject("Excel.Application")
appXl.Workbooks.Open somfile.xls

appXl.Worksheets("Data").Activate
appXl.ActiveSheet.UsedRange.Clear
Set qTable = appXl.ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strCSVFileName, Destination:=Range("A1"))
Set qTable = Nothing
appXl.Worksheets("Report").Activate
appXl.ActiveSheet.PivotTables("PivotTable1").PivotSelect "",
xlDataAndLabel, True
For Each oWorkBook In appXl.Workbooks
oWorkBook.Close SaveChanges:=True
Next
Set oWorkBook = Nothing
appXl.Quit
Set appXl = Nothing


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
N

nitin

Hi
I tried it but didnt work here is new code
Dim appXl As Excel.Applicatio
Dim oWorkBook As Excel.Workboo
Dim qTable As Excel.QueryTabl

Set appXl = CreateObject("Excel.Application"
appXl.Workbooks.Open somfile.xl

appXl.Worksheets("Data").Activat
appXl.ActiveSheet.UsedRange.Clea
Set qTable = appXl.ActiveSheet.QueryTables.Add(Connection:=
"TEXT;" & strCSVFileName, Destination:=Range("A1")
Set qTable = Nothin
appXl.Worksheets("Report").Activat
appXl.ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, Tru
For Each oWorkBook In appXl.Workbook
oWorkBook.Close SaveChanges:=Tru
Nex
Set oWorkBook = Nothin
appXl.Qui
Set appXl = Nothing
 

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