View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ryan H Ryan H is offline
external usenet poster
 
Posts: 489
Default Unprotect Workbook with Function

I unprotect and protect all worksheets in a workbook with a User Defined
Function that returns the password.

Sub MyExample()
ActiveSheet.Unprotect Password()
' do stuff to the worksheet
ActiveSheet.Protect Password()
End Sub

Function Password() As String
Password = "AdTech"
End Function

This works great! But for some reason when I try to unprotect or protect my
workbook I get a Run Time Error. I know the password is "AdTech", because I
can manually unprotect and protect the workbook, but VBA doesn't like to do
it thru code.

Sub MyExample()
ThisWorkbook.Unprotect Password()
' do stuff to the worksheet
ThisWorkbook.Protect Password()
End Sub


Any one have any ideas why?

Thanks in Advance!


--
Cheers,
Ryan