Solved

Unlock Excel Cells Using Macros.

Posted on 2004-09-22
11
560 Views
Last Modified: 2011-10-03
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

0
Comment
Question by:KUMON2004
11 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 43 total points
Comment Utility
Hi AB,

You will have to unprotect the sheet to run the code (locked cells wont do anything otherwise), unless you're protecting it at runtime and adding the UserInterfaceOnly:=True argument to the protect method--I can give you more details about that if you need them. but you should just be able to do
oWoorksSheet.Cells.Locked = False

Matt
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 41 total points
Comment Utility
Are you talking about

'lock
ActiveSheet.Cells.Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


'unlock
ActiveSheet.Unprotect
0
 
LVL 1

Author Comment

by:KUMON2004
Comment Utility
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.
0
 
LVL 4

Expert Comment

by:Prestaul
Comment Utility
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:Prestaul
Comment Utility
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.
0
 
LVL 1

Author Comment

by:KUMON2004
Comment Utility
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
0
 
LVL 4

Assisted Solution

by:Prestaul
Prestaul earned 41 total points
Comment Utility
Use:

ThisWorkbook.Sheets("SheetName").Columns(1).Locked=False
or
ThisWorkbook.Sheets("SheetName").Columns("A").Locked=False
or
ThisWorkbook.Sheets(1).Columns("A").Locked=False
or
ThisWorkbook.ActiveSheet.Columns(1).Locked=False

to lock and unlock column A.  You have to specify a worksheet.
0
 
LVL 4

Expert Comment

by:Prestaul
Comment Utility
Valid answers posted by three people:  mvidas, EDDYKT, and Prestaul.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now