Refresh External Data on Protected Sheet

caelhonig

New Member
Joined
Dec 27, 2015
Messages
4
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.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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.

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.
 
Upvote 0
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.

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
 
Upvote 0
If you look at the code, you will see there is no password provided in the Unprotect method.

Apparently, Excel does not record the password.

Just add the password in both the Unprotect and the Protect statements:

Code:
ActiveWorkbook.Unprotect "mypassword"
and
Code:
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
 
Upvote 0

Forum statistics

Threads
1,215,790
Messages
6,126,911
Members
449,348
Latest member
Rdeane

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top