?
Solved

microsoft.office.interop.excel   and VB.NET.  AllowEdit = false not working

Posted on 2008-09-30
2
Medium Priority
?
1,726 Views
Last Modified: 2012-08-13
I have an excel document that I fill and edit data programatically.  I can protect an entire worksheet no problem, but on one sheet I only want to protect one Cell Range so a user can not edit the value, but can still edit the rest of the worksheet.  I tried using the range.allowedit but I get an error
" Property 'Allow Edit' is Read Only '  How would I write it in vb.net so I can use that read only property?


        Dim cover As Microsoft.Office.Interop.Excel.Worksheet = Doc.Sheets(2)
               cover.Range("N3").AllowEdit = False
0
Comment
Question by:logoncom
[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
2 Comments
 
LVL 12

Accepted Solution

by:
omegaomega earned 2000 total points
ID: 22619769
Hi, logoncom,

I think that perhaps it is the "Locked" property that you are looking for.  Typically, all worksheet cells are locked by default, but this has no effect until the Worksheet is protected.  What you need to do is unlock the cells that you want the user to be able to access (or unlock all cells and then lock the ones that are to be protected).  Then when you protect the Worksheet, only the unprotected cells will be available.

Try something like this:

        Dim xlaTest As Excel.Application = CType(CreateObject("Excel.Application"), Excel.Application)
        Dim wbkNew As Excel.Workbook = xlaTest.Workbooks.Add()
        Dim wshTest As Excel.Worksheet = DirectCast(wbkNew.Worksheets(1), Excel.Worksheet)
        Dim rngUnlocked As Excel.Range = wshTest.Range("C3:E5")
        rngUnlocked.Locked = False
        wshTest.Protect(DrawingObjects:=True, Contents:=True, Scenarios:=True)
        wbkNew.SaveAs("D:\Temp\ProtectedSample.xls")
        wbkNew.Close()
        xlaTest.Quit()

And then notice that only the cells in the range C3:E5 can be edited.

Cheers,
Randy
0
 

Author Closing Comment

by:logoncom
ID: 31501651
Thanks
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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