Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unlock Excel Cells Using Macros.

Posted on 2004-09-22
11
Medium Priority
?
574 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

926 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