A Macro to open Excel so a few

only_sleeping

New Member
Joined
Sep 16, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi Folks, I'm completely out of my depth whilst trying to write a macro that upon opening a protected and shared Excel file will do the following:

Open to a specific worksheet
Zoom to 100%
Clear any previously saved filters on the opened sheets
Allow filtering on all tabs in the sheet.

I currently have this:

VBA Code:
Private Sub Workbook_Open()

Worksheets("Students Data").Activate

ActiveWindow.Zoom = 100









Dim wks As Worksheet



For Each wks In Worksheets



If wks.FilterMode = True Then

wks.UnProtect

wks.ShowAllData

wks.Protect AllowFiltering:=True

End If

Next wks



End Sub

I've cobbled this together from various posts on the internet but not entirely sure what each bit means. Upon opening, I'm getting a "Method 'Unprotect' of object '_Worksheet' failed".

Can anyone help?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

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