Friday, December 5, 2008

Prob St: To edit cells in excelsheet and password protect all used cells (Using VBScript)

  1. Select all cells in the excelsheet. right click, go to 'Format cells' uncheck 'Locked' in protection tab.
  2. Protect the excelsheet using
  3. Then use the following code in the vbscript to accomplish the task.

'*********************************************

Set objExcel = CreateObject("EXCEL.APPLICATION")
Set objWorkBook = objExcel.Workbooks.Open(FilePath)

objExcel.Activesheet.Unprotect "yourpassword "

' Enter you working code here

objExcel.ActiveSheet.UsedRange.Locked = true
'objExcel.Activesheet.protect "yourpassword "

'******************* end of script*****************

No comments: