?
Solved

Unlock Excel Cells Using Macros.

Posted on 2004-09-22
11
Medium Priority
?
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 172 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 164 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 164 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

719 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