Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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