error messages

H

hans

I have an asp-project in wich I open excel to create a graph.
Everything goes fine, but if i want to test the code again, the page
crashes.
I figured out I that the page crashes because the excel-file I want to
open is still being used (allthough I closed it in the previous
session).

Is there a way to show error messages that say what's happening?
Does anyone know why the file is still in use?

I use the following code:

<%
Option explicit
Dim sTemplateFile
Dim sTargetFile
Dim oExcelApp
Dim oExcelWkb
Dim oExcelSht
Dim oChart
Dim oSourceRange

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

Const xlWorkSheet = -4167
Const xlLineMarkers = 65
Const xlNormal = -4143
Const xlLeft = -4131
Const xlCenter = -4108
Const xlRight = -4152

%>
<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
oExcelWkb.SaveAs sTargetFile, xlNormal

'Specify worksheet
set oExcelSht = oExcelWkb.worksheets(1)

'Set 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 oSourceRange, 2, , 2, 1, 0, 2, "a title"

'Quit Excel
oExcelWkb.close true
Set oExcelSht = Nothing
Set oExcelWkb = Nothing
oExcelApp.Quit
Set oExcelApp = 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