envi_ria


Can i protect and unprotect an excel file in VBA.

I need urgent help in this can any one help me out. I have to open some excel files copy all the names of the excel file from that folder and then a copy a corresponding coloum name also in the new excel sheet. But these files will be protected. i will have to open and the file unprotect it copy a data from a pertucular lable name and then lock the cells and protect it back again.

can any one help me wtih this code, i have lost all my files in transist and i need this code urgently.

thanks in advance.





Re: Need urgent help

Andy Pope


Hi,

You should be able to unprotect/protect if you have the password(s).

' worksheet protection
ActiveSheet.Unprotect "password"

ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True

' cell lock
Range("A1").Locked = True
Range("A1").FormulaHidden = False