Leonardo Valverde
Leonardo Valverde

Reputation: 147

VSTO - Lock all cells of excel worksheet without changing selection

I'm developing an application add-in for excel using VSTO, programming in VB.NET. I'm trying to lock (by setting ".locked = true") for all cells in my worksheet, and I'm currently doing it this way:

Me.sheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet
Me.sheet.Cells.Select()
CType(Globals.ThisAddIn.Application.Selection, Excel.Range).Locked = True

The problem is that I want to do it without changing the selection, because it is important to my application.

Any ideas of how to do it? Thank you.

Upvotes: 1

Views: 1004

Answers (1)

Leonardo Valverde
Leonardo Valverde

Reputation: 147

Problem Solved!

Me.sheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet
Me.sheet.Cells.Locked = True

Thank you!

Upvotes: 1

Related Questions