Worksheets.Activate error

Billdub417

New Member
Joined
Nov 5, 2019
Messages
45
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?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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.
 
Upvote 0
Solution
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
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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