Solved

Unlock Excel Cells Using Macros.

Posted on 2004-09-22
11
562 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
ID: 12125322
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
ID: 12125884
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
ID: 12126158
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:Prestaul
ID: 12127102
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
 
LVL 4

Expert Comment

by:Prestaul
ID: 12127133
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
ID: 12127161
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
ID: 12127224
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
ID: 12565566
Valid answers posted by three people:  mvidas, EDDYKT, and Prestaul.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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