Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with unprotecting a spreadsheet 1

Status
Not open for further replies.

EliseFreedman

Programmer
Dec 6, 2002
470
GB
Hi All

Im having an issue with using vba to unprotect data in a spreadsheet

Ive got a master spreadsheet which is protected with a password to stop users fiddling with the data. The spreadsheet contains filters which users can utilise to customise the spreadsheet to fit their own requirements. The filtered data will be exported to another spreadsheet. I am wanting the new spreadsheet to be unprotected.

I have tried the following code to unprotect the newly created spreadsheet but although I can see that the code is running, the sheets are still protected. What am I doing wrong

Code:
Windows("DSEStatusReport.xls").Activate
Set wbNew = ActiveWorkbook
    
    On Error Resume Next
    For Each wSheet In Worksheets
        wSheet.Unprotect Password:="HealthyWorking"
        MsgBox "unprotecting"
    Next wSheet
    If Err <> 0 Then
        MsgBox "You have entered an incorect password. All worksheets could not " & _
        "be unprotected.", vbCritical, "Incorect Password"
    End If
    On Error GoTo 0
 
Is the new workbook named "DSEStatusReport.xls"?

combo
 
Try to unprotect single sheet and explicitly refer to it:
[tt]Workbooks("DSEStatusReport.xls").Worksheets("sheet name here").Unprotect Password:="HealthyWorking"[/tt]
Do you use only basic ASCII characters in your password?

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top