[AccessD] Access To Excel - Best Practices For Protecting Formulas

Mcgillivray, Don [IT] Donald.A.McGillivray at sprint.com
Thu Apr 13 17:40:58 CDT 2006


Larry, 

I've not done this from the Access side, but here's a little procedure
that I keep in my Excel macro stash to invoke protection on the current
workbook.  It can probably be used to do what you're trying to do.

As for the selective protection, each cell in a workbook has a
"protected" property that can be set using the cell's formatting
interface.  When you apply protection, only those cells flagged for
protection will be locked down.  This allows you to be selective with
your protection.  Again, I'm sure you could programatically select a
range of cells, set the protection flags for the range, and then apply
protection using this code.  Bear in mind that you'd have to
programatically un-protect the book to make any automated mods to it
after it's been locked down.

Hope this helps . . .

Don McGillivray


Sub SecureSheets()
'----------------------------------------------------
'This code protects all tabs in the active workbook,
'using the password specified below
'----------------------------------------------------

Dim intCounter As Integer
Dim intSheets As Integer
Dim strPwd As String

intSheets = ActiveWorkbook.Worksheets.Count
'Specify the desired password between the quotes in the line below

        strPwd = "password"

For intCounter = 1 To intSheets
    ActiveWorkbook.Worksheets(intCounter).Protect password:=strPwd
Next
End Sub





More information about the AccessD mailing list