View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

How do you unprotect the worksheet?

If you let the user do it manually, you can't capture it.

If you use code to display that unprotect dialog, you can't capture it.

But you could use an inputbox (or userform to mask the password) and ask the
user for it.

Then have your code unprotect, do its stuff and then reprotect.

Kind of...

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim myPwd As String
Dim SheetWasProtected As Boolean

Set wks = Worksheets("sheet1")

With wks
SheetWasProtected = False
If .ProtectContents _
Or .ProtectDrawingObjects _
Or .ProtectScenarios Then
SheetWasProtected = True
myPwd = InputBox(Prompt:="what's the passwork, kenny?")
On Error Resume Next
.Unprotect Password:=myPwd
If Err.Number < 0 Then
MsgBox "Wrong password, try later!"
Err.Clear
Exit Sub
End If
On Error GoTo 0

'do your stuff

If SheetWasProtected Then
.Protect Password:=myPwd
End If
End If
End With
End Sub



Vic wrote:

I have developed a personal tracking spreadsheet that I
occasionally send out an up-dated version to those using
it. The spreadsheet will automatically up-date the data
into the new version and save it under the same name. The
user simply clicks a data transfer button and is given the
opportunity to open the existing spreadsheet and transfer
the data to the new version. The problem is that I don't
know how to capture the password to include that in the
new up-dated spreadsheet so that the user doesn't have to
re-enter the password during the first save after the up-
date. Is it possible to capture the password of the
opened spreadsheet and save the new version with the same
password? Any help would be appreciated. Thanks!


--

Dave Peterson