Microsoft Office Tutorials and References
In Depth Information
Worksheet protection is useful in many scenarios. A workbook may contain more than
one worksheet and if the owner of the workbook wants to protect or hide one or more
specific worksheets from other users then it can be done in Microsoft Office Excel.
Let's see how to protect the worksheet from public users with the help of a password.
Open Visual Studio 2008 and create a new solution, as before. Write the following
code inside the ThisWorkbook.cs file:
private void Sheet1_Startup(object sender, System.EventArgs e)
// This will protect the Worksheet with password from
editing by the public users
Globals.Sheet1.Protect("MyPassword", missing, missing,
missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, true, missing,
In this section, you have learned the basic concepts of protecting the workbook and
worksheet using VSTO and C# programming. You can also implement a custom
algorithm for password security to tighten the strength of protection.
In this chapter, we focused on the basic functionality of the Microsoft Office Excel
2007 spreadsheet application. At the beginning of this chapter, we discussed data
manipulation, Excel workbooks, and Excel worksheet manipulation. We have seen
several ways of data processing through VSTO and C# in Microsoft Office Excel
2007, to help you learn the flexible ways of data processing for Excel. Reading
further, you learned the concept of the object model in Excel and more about the
Range object in the Excel object model. This chapter covered significant features
for working with cells using Range objects. In the later part of the chapter, we
learned more about how smart tags can be created using VSTO. This chapter also
covered Excel host items and Excel host controls. We took a look at events that are
exposed by Excel host items, with code snippets. We learned how VSTO helps Office
developers to build Excel solutions with all of the basic features such as formulae
and expressions. And, finally we saw how to secure an Excel workbook using VSTO.