Friday, April 23, 2010

Unprotect and Protect Sheet using VBA code

How to write to protected Excel file using VBA

Here is a sample to unprotect a sheet and write some values and then protect the sheet again


Sub Unprotect_And_ThenProtect()
    
    ActiveSheet.Unprotect
    Range("A2").Value = Now()
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub

No comments:

Post a Comment

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...

Visual Basic for Applications (VBA) Forum (recent threads)

CodeKeep VBA Feed

Visual Studio Tools for Office Forum (recent threads)

Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.

Office Business Applications (OBA) Team Blog

MSDN Code Gallery Published Resources For Tag VSTO

microsoft.public.vsnet.vstools.office Google Group