Some Code Doesn't Work on New Install of Excel 2003

throtmorton

Board Regular
Joined
Aug 9, 2005
Messages
94
Office Version
  1. 365
Platform
  1. Windows
Hi,

My old XP hard drive died, so I got a new one. Installed Excel 2003, and my file works fine. However, this routine not only doesn't work, but crashes Excel. It worked fine before, and still works find on my Vista machine.

Very much appreciate any help!

Thanks,
Paul

Here's the error message:

Run-time error '1004':
Method 'Protect' of object'_Worksheet' failed

******

Option Explicit

Public Const strPassWord = "y"

******

Sub Protect()

Application.ScreenUpdating = False

Dim wSheet As Worksheet

For Each wSheet In Worksheets
wSheet.Protect Password:=strPassWord
Application.ScreenUpdating = True

Next wSheet

Application.ScreenUpdating = True

End Sub
 

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
Not sure but the screen updating = true shouldn't be in the loop. Maybe activate is needed? HTH. Dave
Code:
For Each wSheet In Worksheets
'wsheet.activate ????
wSheet.Protect Password:=strPassWord
Next wSheet
 
Upvote 0

Forum statistics

Threads
1,207,402
Messages
6,078,264
Members
446,324
Latest member
JKamlet

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