Link to home
Start Free TrialLog in
Avatar of KUMON2004
KUMON2004

asked on

Unlock Excel Cells Using Macros.

Hello,
I am generating Excel Files using a template from a ActiveXControl.When I generate the file at the End i lock all the cells using,
oWoorksSheet.Cells.Locked = True
Now,When i Open the File Using Excel I wants to Unlock the Cells if the User selects to Enable the Macro.
Need Help ASAP.
Thank You
AB

ASKER CERTIFIED SOLUTION
Avatar of mvidas
mvidas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KUMON2004
KUMON2004

ASKER

HI,
Once i am done creating the excel file..i wants to lock all the cells or make the whole worksheet readonly....
When the person for whom the system creates this excel file will open the file ....if he disable the macros the file shd  remain lock.
But if he enables the macro then i need to put the code that unlock the cells.
But I dont want to unlock all the cells there r few cells that will still remain locked.
I m Using oWoorksSheet.Cells.Locked = True to lock the file....How would i unlock it in the VBA Project(Macro)
Any Help will be appreciated.
Thank  You
AB.
KUMON2004, you want the code that EDDYKT posted.  Try that in place of what you are using and it will work fine.  Put the unlock code in the Workbook_Open event and the lock code in the Workbook_BeforeClose event.  Also you shouldn't need the select line so you can remove:

ActiveSheet.Cells.Select
The code above will lock all cells by default.  To unlock individual cells select them, right-click and then select format cells.  Goto the Protection tab and uncheck the Locked option.  Now when you lock the sheet (as above in EDDYKT's post) those cells will still be edittable, the rest will not.
I want to unlock the individual cells using vba code NOt using normalexcel steps.
I am trying to use Columns("A").Locked=False But its not working..its strange ....
You have any idea....
Thank YOU
AB
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Valid answers posted by three people:  mvidas, EDDYKT, and Prestaul.