1
votes

Please help me.

I want to create excel file with data and full write permission(Everyone user) using asp(vb script).

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Add()

objWorkbook.SaveAs(strFileName)

I used this method for create excel file but this excel file get readonly permission. So, how i need to do for write permission and how to insert data into this excel file.

Thanks

3
how are your users editing the document? through another web page or Excel directly?user69820

3 Answers

1
votes
 strPathExcel="c:\myExcelFile.xlsx"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.SaveAs strPathExcel

'========== change the premission for Everyone to Modify ===============
 CreateObject("Wscript.Shell").Run "ICACLS """& strPathExcel & """ /grant everyone:M ",0,False

'====== how to write inside excel sheet you just create and save then close ======= 
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' write to  a cell.
objSheet.Cells(3, 2).Value = "Test"

' Add a row before row 5.
objSheet.Range("B5").EntireRow.Insert

' Label the new rows. Row 4 is unchanged, but what was row 5 is now row 6.
objSheet.Cells(4, 1).Value = "Row 4"
objSheet.Cells(5, 1).Value = "Row 5"
objSheet.Cells(6, 1).Value = "Row 6"

' Save the change  and quit.
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
0
votes

I'm not sure why it's being made read-only, but you can use the the SetAttr function to change the file permissions to be writeable. This page has more information and some sample code.

0
votes

I've run into this before. You must quit excel or close the workbook once you are done. As long as Excel is running and the workbook is open, it will always be read only. Once your script is finished doing what it needs to the excel file, save it (as you are doing), but Close it too. In a perfect world, close the excel object and set it to nothing as well. Try adding the following at the end of your script:

objWorkbook.Close
Set objWorkbook = Nothing  '<-- not needed if at the end of the script.
objExcel.Close
Set objExcel = Nothing     '<-- not needed if at the end of the script.

Remember, Excel is, by it's very nature, a single user environment.