Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel+ASP - Document not saved error help!!

Status
Not open for further replies.

hardcoder

Programmer
Feb 16, 2002
17
US
I use the following code to copy a file on the root folder, in an ASP page:

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile(Server.MapPath("OldFile.xls"))
newFileName = "NewFile_" & datepart("m", now()) & "_" & datepart("yyyy", now()) & "_" & datepart("s", now()) & ".xls"
MyFile.Copy (Server.MapPath(newFileName))

This works fine.
But then I use the Excel library to open the file, add some rows, and then save it, when I get the Document Not saved Error.

Code to open excel file:
Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(Server.MapPath(newFileName))
Set oWS = oWB.Worksheets("Sheet2")

Code to save and close the Excel file:
Set oWS = Nothing
oWB.Save
oWB.Close False
Set oWB = Nothing
oXL.Quit
Set oXL = Nothing


Please help me out!! How do I get rid of this error? Is it a permissions problem? Does the XL library lock the file??? Lyra Computing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top