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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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