Solved

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

Posted on 2008-09-30
2
1,632 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
2 Comments
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now