Very urgent help needed: Excel is still running after closing it!

H

hans

Hi,

I need some help with this one:

I open an excel-file (testfile.xls) that contains some testing data.
Next I create a chart, based on that testing data and save the file as
result.xls.
If I completed all that, I quit the application and set everything to
nothing. Untill there, everything goes fine, but if I want to test this
sample code again, it's not possible anymore because "result.xls" is
still in use!!!

Can somebody tell me how to make sure excel closes completely after
saving result.xls?

I'm using office 2003 and the code is in ASP.

Dim sTemplateFile
Dim sTargetFile
Dim oExcelApp ' Our Excel App
Dim oExcelWkb ' Our Workbook within the Excel App
Dim oExcelSht ' Our Worksheet within the Workbook
Dim oChart ' The chart object
Dim oSourceRange ' The Source Range for the chart object

'File system object
Dim oFSO

'Constants (Excel)
Const xlWorkSheet = -4167
Const xlLineMarkers = 65
Const xlNormal = -4143
Const xlLeft = -4131
Const xlCenter = -4108
Const xlRight = -4152

sTemplateFile = Server.MapPath("\pro2006") & "\testfile.xls"
sTargetFile = Server.MapPath("\pro2006") & "\result.xls"

'Delete old target file
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(sTargetFile) Then oFSO.DeleteFile(sTargetFile)
Set oFSO = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Create report</title>
</head>
<body>
<%
'Create an instance of Excel Application
Set oExcelApp = Server.CreateObject("Excel.Application")
'Open template
Set oExcelWkb = oExcelApp.Workbooks.open(sTemplateFile)
'Save copy in download folder
oExcelWkb.SaveAs sTargetFile, xlNormal
'Specify worksheet
set oExcelSht = oExcelWkb.worksheets(1)

'Set our source range
Set oSourceRange = oExcelSht.Range("A2:B7")
'Create a new Chart Object
Set oChart = oExcelSht.ChartObjects.Add(20, 20, 300, 200)

oChart.Chart.ChartWizard , 2, , 2, 1, 0, 2, "chart title"

Set oExcelSht = Nothing
oExcelWkb.close true
Set oExcelWkb = Nothing
oExcelApp.Quit
Set oExcelApp = Nothing
 
P

Peter T

Try releasing oSourceRange and oChart by setting both to Nothing before you
close the file.

Regards,
Peter T
 
H

hans

That indeed did the trick. Stupid I overlooked this...
Thanks a lot for your help!
 

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