sanfranqsr
IS-IT--Management
Hi All -
I have this code in a web page that pulls data out of excel and displays the data. This code runs three times within the web page (all with distinct variables) to pull from three different worksheets.
Code runs fine 95% of the time, the other 5% I wind up with a cannot create object error. For some reason one of the instances of Excel remains running and has to be manually quit through task manager. The web page reloads itself every 5 minutes, so I usually get the error once a day.
Anyone have any ideas on what is causing the error? My guess is I have a minor flaw in the way I am closing the objects.
Thanks!
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Dim objApp, objWbs, objWorkbook, objSheet, Revenue, GuestTotal
Dim Guests1, Guests2, Guests3, Guests4, Guests5
Set objApp = CreateObject("Excel.Application")
Set objWbs = objApp.WorkBooks
objApp.Visible = False
Set objWorkbook = objWbs.Open("c:\alohasubs\mg1\hourly.csv")
Set objSheet = objWorkbook.Sheets("hourly")
Revenue = objSheet.Range("B24").Value
Guests1 = objSheet.Range("C13").Value
Guests2 = objSheet.Range("C14").Value
Guests3 = objSheet.Range("C15").Value
Guests4 = objSheet.Range("C16").Value
Guests5 = objSheet.Range("C17").Value
GuestTotal = objSheet.Range("C24").Value
objWorkbook.Close False
objWbs.Close
objApp.Quit
Set objSheet = Nothing
Set objWorkbook = Nothing
Set objWbs = Nothing
Set objApp = Nothing
document.write("<font face=arial><table cellpadding=0 background=#FFFFFF border=1 bordercolor=#ffffff><tr bgcolor=#fffff><td><center>11:30</center></td><td><center><b>")
document.write(Guests1)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center>12:00</center></td><td><center><b>")
document.write(Guests2)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center>12:30</center></td><td><center><b>")
document.write(Guests3)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center> 1:00</center</td><td><center><b>")
document.write(Guests4)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center> 1:30</center></td><td><center><b>")
document.write(Guests5)
document.write("</b></center></td></tr><tr bgcolor=#ffffff><td><center><b><h1>")
document.write("$")
document.write(Revenue)
document.write("</h1></center></b></td><td><center><b><h1>")
document.write(GuestTotal)
document.write("<h1></b></center></td></tr></table></font>")
</script>
I have this code in a web page that pulls data out of excel and displays the data. This code runs three times within the web page (all with distinct variables) to pull from three different worksheets.
Code runs fine 95% of the time, the other 5% I wind up with a cannot create object error. For some reason one of the instances of Excel remains running and has to be manually quit through task manager. The web page reloads itself every 5 minutes, so I usually get the error once a day.
Anyone have any ideas on what is causing the error? My guess is I have a minor flaw in the way I am closing the objects.
Thanks!
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Dim objApp, objWbs, objWorkbook, objSheet, Revenue, GuestTotal
Dim Guests1, Guests2, Guests3, Guests4, Guests5
Set objApp = CreateObject("Excel.Application")
Set objWbs = objApp.WorkBooks
objApp.Visible = False
Set objWorkbook = objWbs.Open("c:\alohasubs\mg1\hourly.csv")
Set objSheet = objWorkbook.Sheets("hourly")
Revenue = objSheet.Range("B24").Value
Guests1 = objSheet.Range("C13").Value
Guests2 = objSheet.Range("C14").Value
Guests3 = objSheet.Range("C15").Value
Guests4 = objSheet.Range("C16").Value
Guests5 = objSheet.Range("C17").Value
GuestTotal = objSheet.Range("C24").Value
objWorkbook.Close False
objWbs.Close
objApp.Quit
Set objSheet = Nothing
Set objWorkbook = Nothing
Set objWbs = Nothing
Set objApp = Nothing
document.write("<font face=arial><table cellpadding=0 background=#FFFFFF border=1 bordercolor=#ffffff><tr bgcolor=#fffff><td><center>11:30</center></td><td><center><b>")
document.write(Guests1)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center>12:00</center></td><td><center><b>")
document.write(Guests2)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center>12:30</center></td><td><center><b>")
document.write(Guests3)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center> 1:00</center</td><td><center><b>")
document.write(Guests4)
document.write("</b></center></td></tr><tr bgcolor=#fffff><td><center> 1:30</center></td><td><center><b>")
document.write(Guests5)
document.write("</b></center></td></tr><tr bgcolor=#ffffff><td><center><b><h1>")
document.write("$")
document.write(Revenue)
document.write("</h1></center></b></td><td><center><b><h1>")
document.write(GuestTotal)
document.write("<h1></b></center></td></tr></table></font>")
</script>