Solved

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

Posted on 2008-09-30
2
1,622 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

13 Experts available now in Live!

Get 1:1 Help Now