PDA

View Full Version : password protection difference



av8tordude
01-24-2012, 04:16 PM
Is there any difference in the two codes below when protecting a sheet or workbook? Is there a preferred method?

Protect Password:="12345"
Protect "12345"

Kenneth Hobs
01-24-2012, 05:03 PM
Protect means nothing without an object that contains the method.

Password is the parameter name for the worksheet or workbook object's Protect method. Named parameters are handy when you want to skip order. e.g.
ThisWorkbook.Protect "ken", UserInterfaceOnly:=True

av8tordude
01-24-2012, 05:17 PM
I understand you need an object like ThisWorkbook.Protect, but I have seen both methods used as mentioned above. So is there any difference and is there a preferred method?

Kenneth Hobs
01-24-2012, 05:25 PM
By observation, you can see that since it is the first parameter, the parameter name is not required. Using it does make it clear what you are doing with that first parameter. It does take longer to type. You decide what you like best about the option to type the parameter name or not when order is not in play.

av8tordude
01-24-2012, 05:54 PM
Thank you Ken for the explanation.

Paul_Hossler
01-24-2012, 06:53 PM
It can also save a lot of comma-counting like in the second call below



Option Explicit
Sub drv()
Call PassParamaters(, , , , , , , 100)
PassParamaters P8:=200
End Sub

Sub PassParamaters(Optional P1 As Long = 0, _
Optional P2 As Long = 0, _
Optional P3 As Long = 0, _
Optional P4 As Long = 0, _
Optional P5 As Long = 0, _
Optional P6 As Long = 0, _
Optional P7 As Long = 0, _
Optional P8 As Long = 0)
MsgBox P8
End Sub


Paul