The code I am using below works fine with vb.net console applications running on the same server. However, this code returns an access denied error while trying to open excel. I have narrowed the problem down to there by logging events as they occur. Both the file location I am trying to open and the excel.exe directory on the server have been set to allow access to "everyone" and "ASPNET". My web project has both .NET and COM references for Office excel 10.0 (2002), which is the version I am running. Any ideas?
code:
Sub sendreport_purge(ByVal area, ByVal by, ByVal email, ByVal eventdate, ByVal loc, ByVal time, ByVal ori, ByVal pr, ByVal vol, ByVal com, ByVal AFE)
Try
Dim xlApp As New Excel.Application() Lauch excel
Dim books As Excel.Workbooks = xlApp.Workbooks
** ERROR OCCURS PRIOR TO THIS LINE **
Dim book As Excel.Workbook = books.Open("f:\gasmeasurement\meas files\gas loss reports\gas loss report.xls")
Dim sheets As Excel.Sheets = book.Worksheets
Dim j As Integer, currentsheet As Excel.Worksheet
currentsheet = book.Worksheets("Gas Loss")
load data into excel
With currentsheet
.Range("J4").Value = area
.Range("J6").Value = by
.Range("J8").Value = "Vent/Purge"
.Range("AM4").Value = eventdate
.Range("AM6").Value = Format(Date.Today, "MM/dd/yyyy")
.Range("T26").Value = loc
.Range("T28").Value = ori
.Range("T30").Value = vol
.Range("AM26").Value = time
.Range("AM28").Value = pr
.Range("G52").Value = com
.Range("T54").Value = AFE
.Range("T56").Value = Format(Date.Today, "MM/dd/yyyy")
End With
Dim newname, now As String
now = Format(Date.Now, "MM/dd/yyyy hh:mm")
newname = "f:\gasmeasurement\meas files\gas loss reports\" & eventdate & area & now & ".xls"
book.SaveAs(newname)
book.Close(False)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets)
System.Runtime.InteropServices.Marshal.ReleaseComObject(currentsheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(books)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
code:
Sub sendreport_purge(ByVal area, ByVal by, ByVal email, ByVal eventdate, ByVal loc, ByVal time, ByVal ori, ByVal pr, ByVal vol, ByVal com, ByVal AFE)
Try
Dim xlApp As New Excel.Application() Lauch excel
Dim books As Excel.Workbooks = xlApp.Workbooks
** ERROR OCCURS PRIOR TO THIS LINE **
Dim book As Excel.Workbook = books.Open("f:\gasmeasurement\meas files\gas loss reports\gas loss report.xls")
Dim sheets As Excel.Sheets = book.Worksheets
Dim j As Integer, currentsheet As Excel.Worksheet
currentsheet = book.Worksheets("Gas Loss")
load data into excel
With currentsheet
.Range("J4").Value = area
.Range("J6").Value = by
.Range("J8").Value = "Vent/Purge"
.Range("AM4").Value = eventdate
.Range("AM6").Value = Format(Date.Today, "MM/dd/yyyy")
.Range("T26").Value = loc
.Range("T28").Value = ori
.Range("T30").Value = vol
.Range("AM26").Value = time
.Range("AM28").Value = pr
.Range("G52").Value = com
.Range("T54").Value = AFE
.Range("T56").Value = Format(Date.Today, "MM/dd/yyyy")
End With
Dim newname, now As String
now = Format(Date.Now, "MM/dd/yyyy hh:mm")
newname = "f:\gasmeasurement\meas files\gas loss reports\" & eventdate & area & now & ".xls"
book.SaveAs(newname)
book.Close(False)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets)
System.Runtime.InteropServices.Marshal.ReleaseComObject(currentsheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(books)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
xlApp = Nothing