In an Excel macro I need to unprotect a sheet, refresh the data and then protect the sheet. The following works:
Dim rs As Worksheet
For Each rs In Worksheets
rs.Unprotect Password:="SomePassword"
Next rs
ActiveWorkbook.RefreshAll
This does not:
Dim rs As Worksheet
For Each rs In Worksheets
rs.Unprotect Password:="SomePassword"
Next rs
ActiveWorkbook.RefreshAll
For Each rs In Worksheets
rs.Protect Password:="SomePassword"
Next rs
Produces the following error:
The cell or chart you are trying to change is protected and therefore read-only.
I've tried MANY methods to delay the continuing of the macro until the refresh is finished but nothing has worked. I've looked at methods on this forum and found none that work. What will work?