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
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