Solved

Unlock Excel Cells Using Macros.

Posted on 2004-09-22
11
565 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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