Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 87
location of a form 2 33
FInd Image Control Gridview 3 38
VB.net Duplicating a table - primary key not created 3 38
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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