Skip to content

Instantly share code, notes, and snippets.

@summerofgeorge
Created December 24, 2017 20:23
Show Gist options
  • Select an option

  • Save summerofgeorge/6f8d4d949707f4df33d9c0af04546d3d to your computer and use it in GitHub Desktop.

Select an option

Save summerofgeorge/6f8d4d949707f4df33d9c0af04546d3d to your computer and use it in GitHub Desktop.
Excel - Refresh data in locked worksheet
'Refresh data in a protected worksheet
'Source: https://www.extendoffice.com/documents/excel/4379-excel-protect-sheet-but-allow-data-refresh.html
'Save workbook as .xlsm, hit Alt+F11, and paste the following code into the MODULES section of your workbook:
Sub DataRefresh()
ActiveSheet.Unprotect
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:01"), "DataRefresh2"
End Sub
Sub DataRefresh2()
If Application.CommandBars.GetEnabledMso("RefreshStatus") Then
Application.OnTime Now + TimeValue("00:00:01"), " DataRefresh2"
Else
ActiveSheet.Protect
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment