#1   Report Post  
Posted to microsoft.public.excel.misc
David
 
Posts: n/a
Default Type Mismatch Error

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   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Type Mismatch Error

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   Report Post  
Posted to microsoft.public.excel.misc
David
 
Posts: n/a
Default Type Mismatch Error

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handler Not Working Bill Excel Discussion (Misc queries) 0 August 25th 05 07:13 PM
Database Query -- Data Type Mismatch StephenP Excel Discussion (Misc queries) 0 April 14th 05 07:05 PM
Type mismatch on LastRow daniel chen Excel Discussion (Misc queries) 8 April 11th 05 02:29 AM
ERROR Pinto1uk Excel Discussion (Misc queries) 1 February 8th 05 03:15 AM
Excel error - Startup (and Acrobat PDFMaker) gxdata Setting up and Configuration of Excel 0 February 4th 05 03:44 AM


All times are GMT +1. The time now is 01:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"