What's wrong with this code.

thunderfoot

Board Regular
Joined
May 28, 2004
Messages
229
All I want the code below to do is to Protect the workbook with whatever entry is in the 'Named Range'. The Named Range "Password_WB" is a cell in another unhidden (and unprotected) worksheet.

I'm getting :- Runtime error 5. Invalid Procedure Call or Argument.
What's wrong with this code??? I can't spot the error!!

Sub Macro4()
'
' Keyboard Shortcut: Ctrl+y
'
ActiveWorkbook.Protect Range("Password_WB"), Structure:=True, Windows:=False
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello,

try:

ActiveWorkbook.Protect Range("Password_WB").Value, Structure:=True, Windows:=False

martin
 
Upvote 0
Thunder,

Try declaring the password as a variable first, then use that in the protect line. Something like this, but this isn't tested....

Code:
Dim PWord As String
PWord = Range("Password_WB").Text
ActiveWorkbook.Protect (PWord), Structure:=True, Windows:=False

Bob

Edit - Or what Martin said ! lol
 
Upvote 0

Forum statistics

Threads
1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

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