LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Runtime Error '1004'

Previously, I received a runtime error '9': Subscript out of range. Now I
get a runtime error '1004': Unable to set the Visible property of the
Worksheet class at
Sheets(sSName).Visible = True
in the code below.

Does anyone have an idea of what other causes there could be?

Perhaps someone could design a workbook and see if the result is the same.
The instructions are at
http://exceltips.vitalnews.com/Pages...by_User.htm l.

Dim bOK2Use As Boolean

Private Sub btnOK_Click()
Dim bError As Boolean
Dim sSName As String
Dim p As DocumentProperty
Dim bSetIt As Boolean

bOK2Use = False
bError = True
If Len(txtUser.Text) 0 And Len(txtPass.Text) 0 Then
bError = False
Select Case txtUser.Text
Case "Austin"
sSName = "Corp"
If txtPass.Text < "u1pass" Then bError = True
Case "Tejas"
sSName = "Elect"
If txtPass.Text < "u2pass" Then bError = True
Case Else
bError = True
End Select
End If
If bError Then
MsgBox "Invalid User Name or Password"
Else
'Set document property
bSetIt = False
For Each p In ActiveWorkbook.CustomDocumentProperties
If p.Name = "auth" Then
p.Value = sSName
bSetIt = True
Exit For
End If
Next p
If Not bSetIt Then
ActiveWorkbook.CustomDocumentProperties.Add _
Name:="auth", LinkToContent:=False, _
Type:=msoPropertyTypeString, Value:=sSName
End If

Sheets(sSName).Visible = True
Sheets(sSName).Unprotect (txtPass.Text)
Sheets(sSName).Activate

bOK2Use = True
Unload UserForm1
End If
End Sub

Private Sub UserForm_Terminate()
If Not bOK2Use Then
ActiveWorkbook.Close (False)
End If
End Sub
 
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
runtime error 1004 HELP PLS Marcelo P Excel Discussion (Misc queries) 2 May 23rd 07 08:56 PM
Runtime Error 1004 - Help Dean[_9_] Excel Programming 4 March 24th 06 06:54 AM
What causes runtime error 1004? [email protected] Excel Discussion (Misc queries) 4 October 27th 05 07:15 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 Gary[_4_] Excel Programming 1 October 10th 03 02:21 PM


All times are GMT +1. The time now is 12:27 AM.

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"