View Single Post
  #1 (permalink)  
Old April 14th, 2004, 10:35 AM
hems hems is offline
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Editing Unlocked cells in VBA

Hi,

I need some inputs on how to,
1) Write into a protected, but unlocked cells through VBA
2) Get the password of the excel sheet in the VB code directly.

1) I had protected my excel sheet with a password. When the sheet is protected, all the cells becomes read-only. So I unlocked few cells that I had to edit by using 'Format Cells-> Protection -> Uncheck Locked' in the excel sheet. So now I am able to edit the values in those unlocked cells through VBA without unprotecting the sheet.

The question here is, when I try to edit those cells through VBA code like assigning some value to that cell, it gives an error stating that the cell is protected. Why does it behave so inspite of the cells being unlocked. Let me know the steps to edit values in protected sheet and unlocked cells through VBA.

One more strange behavior related to this which I observed is, I tried to unlock a range of cells and then protected the sheet. When I tried to edit the cells one by one, the first editing worked, and the rest failed. Also when I unprotected the sheet and saw the cells states, the cells were locked back. Could someone explain this behavior as well?

2) Since I was stuck up with the above scenario, I went with 'Unprotect' -ing the sheet with the password supplied when protecting the sheet, edited the values in those cells and then 'Protect'-ed it back. Here I had to hardcode the password. So it is visible and each time the password in the excel sheet is changed, here too it has to be changed. I have protected my VBA code, but still I would like to know, is there any way in VBA to avoid this.

TIA,
sham

Reply With Quote