Worksheets.Activate error

Billdub417

New Member
Joined
Nov 5, 2019
Messages
32
Hello,

Hopefully, someone can help, it seems trivial but I can't see what's going wrong. Thanks in advance!

I have an excel document with the coding as follows (to password protect each sheet on opening and then finish back on the Home page at the end):

VBA Code:
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="abc123", AllowFiltering:=True, UserInterfaceOnly:=True
Next ws
Worksheets("Home").Activate
Application.ScreenUpdating = True
End Sub

This works fine on my local PC, however, when I sent this spreadsheet to someone and they enabled editing, they are receiving an error message - Run-time error '1004': Activate method of Worksheet class failed.

This is then pointing to the "Worksheets("Home").Activate" line

Any ideas why this would be?
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,533
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Did the workbook open in protected view? If so, you'd get that error the first time that it is enabled (you'd need to use a Workbook_Activate event instead for that case) but it should work fine after the first time.
 
Solution

Billdub417

New Member
Joined
Nov 5, 2019
Messages
32
Did the workbook open in protected view? If so, you'd get that error the first time that it is enabled (you'd need to use a Workbook_Activate event instead for that case) but it should work fine after the first time.
Hello RoryA,

Yes, this is coming up as protected View.

so what would I need to add in "ThisWorkbook" to stop it doing this?

thanks for your guidance
 

Watch MrExcel Video

Forum statistics

Threads
1,128,107
Messages
5,628,731
Members
416,333
Latest member
Time2Learn

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
Top