PDA

View Full Version : Sub only works when stepping in to



jmenche
03-11-2011, 08:53 AM
Riddle me this. This sub ONLY works when I put a stop on the unprotect line and F8 my way through. If I run it normally...the ultimate goal...it gives me a "cell is protected..." error as if the refresh command fired before the unprotect command had a chance to do it's thing.

Can anyone explain?

:beerchug:

Sub refresh()
Dim ws As Worksheet
Set ws = ActiveSheet

ws.Unprotect Password:="itsc"
ActiveWorkbook.RefreshAll
ws.Protect Password:="itsc"

End Sub

Rob342
03-11-2011, 01:19 PM
I created a workbook & set the password as you have
so sheet 1 was protected then pressed F8 to debug, it unprotected the sheet, carried out the refresh then reset the sheet password again.

All worked ok for me