Hi all,
Hideously poor newbie at VBA here. Need a macro that unprotects the sheet "Email", refreshes the external data connections on the sheet (refresh all), then protects the "Email" Sheet again. Any help appreciated.
Thank you.
In most cases, you can get Excel to give you the necessary code:
Turn on the macro recorder, do whatever you want through the UI, turn off the recorder, and check the VB Editor.
Sub Macro2()'
' Macro2 Macro
'
'
ActiveWorkbook.Unprotect
Sheets("OPR").Select
Sheets("Email").Visible = True
ActiveWorkbook.RefreshAll
Sheets("Email").Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.Protect Structure:=True, Windows:=False
End Sub
ActiveWorkbook.Unprotect "mypassword"
ActiveWorkbook.Protect "mypassword", Structure:=True, Windows:=False
Thanks.
Tried this:
Code:Sub Macro2()' ' Macro2 Macro ' ' ActiveWorkbook.Unprotect Sheets("OPR").Select Sheets("Email").Visible = True ActiveWorkbook.RefreshAll Sheets("Email").Select ActiveWindow.SelectedSheets.Visible = False ActiveWorkbook.Protect Structure:=True, Windows:=False End Sub
Getting error: The password you supplied is not corried (run-time error '1004'):
ActiveWorkbook.Unprotect