Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
When using the following code with Type 1, numbers, it works perfect. But
when I change the type to 2 (String) to use text as the password, I get a mismatch error. Can anyone help? Thanks! Sub ProtectAllSheets() ' Dim Password As String Password = CLng(Application.InputBox(Prompt:="What Password Do You Want To Use?", Type:=2)) If Password < 1 Then 'do nothing Else Worksheets(1).Activate ActiveSheet.Protect (Password) End If End Sub |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
You can't cast a string to a long when it is not a number string
Sub ProtectAllSheets() ' Dim Password As String Password = Application.InputBox(Prompt:="What Password Do You Want To Use?", Type:=2) If Password = "False" Then 'do nothing Else Worksheets(1).Activate ActiveSheet.Protect (Password) End If End Sub -- HTH Bob Phillips (remove nothere from email address if mailing direct) "David" wrote in message ... When using the following code with Type 1, numbers, it works perfect. But when I change the type to 2 (String) to use text as the password, I get a mismatch error. Can anyone help? Thanks! Sub ProtectAllSheets() ' Dim Password As String Password = CLng(Application.InputBox(Prompt:="What Password Do You Want To Use?", Type:=2)) If Password < 1 Then 'do nothing Else Worksheets(1).Activate ActiveSheet.Protect (Password) End If End Sub |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Found it! Took the CLng out of the InputBox line and it works great.
"David" wrote: When using the following code with Type 1, numbers, it works perfect. But when I change the type to 2 (String) to use text as the password, I get a mismatch error. Can anyone help? Thanks! Sub ProtectAllSheets() ' Dim Password As String Password = CLng(Application.InputBox(Prompt:="What Password Do You Want To Use?", Type:=2)) If Password < 1 Then 'do nothing Else Worksheets(1).Activate ActiveSheet.Protect (Password) End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error Handler Not Working | Excel Discussion (Misc queries) | |||
Database Query -- Data Type Mismatch | Excel Discussion (Misc queries) | |||
Type mismatch on LastRow | Excel Discussion (Misc queries) | |||
ERROR | Excel Discussion (Misc queries) | |||
Excel error - Startup (and Acrobat PDFMaker) | Setting up and Configuration of Excel |