Hide Command Buttons & Worksheets

iecalpoly

New Member
Joined
Nov 5, 2009
Messages
5
I cannot figure out why my code will not hide command buttons or worksheets based on a given password. I have attached the code so please help me out.

Code:
Private Sub Workbook_Open()
Dim strUser As String, strPassword As String
strUser = InputBox("Enter User Name")
strPassword = InputBox("Enter Password")
Select Case strUser
Case "O"
If strUserPassord = "O4" Then
ActiveWorkbook.Sheets("Main").Select
O.Enabled = True
GOODBYE.Enabled = True
S.Enabled = False
R.Enabled = False
A1.Enabled = False
A3.Enabled = False
A4.Enabled = False
Sheets("Set4").Visible = True
Sheets("Set5").Visible = False
Sheets("Set61").Visible = False
Sheets("Set63").Visible = False
Sheets("Set64").Visible = False
Sheets("Set7").Visible = False
Sheets("File").Visible = False
Sheets("Fild").Visible = True
Sheets("Ts").Visible = True
Sheets("26d").Visible = False
Sheets("263d").Visible = False
End If
Case "S"
If strUserPassord = "O5" Then
ActiveWorkbook.Sheets("Main").Select
O.Enabled = False
GOODBYE.Enabled = True
S.Enabled = True
R.Enabled = False
A1.Enable = False
A3.Enabled = False
A4.Enabled = False
Sheets("Set4").Visible = False
Sheets("Set5").Visible = True
Sheets("Set61").Visible = False
Sheets("Set63").Visible = False
Sheets("Set64").Visible = False
Sheets("Set7").Visible = False
Sheets("File").Visible = False
Sheets("Fild").Visible = True
Sheets("Ts").Visible = True
Sheets("261d").Visible = False
Sheets("263d").Visible = False
End If
Case "A"
If strUserPassord = "O6" Then
ActiveWorkbook.Sheets("Main").Select
O.Enabled = False
GOODBYE.Enabled = True
S.Enabled = False
R.Enabled = False
A1.Enable = True
A3.Enabled = True
A4.Enabled = True
Sheets("Set4").Visible = False
Sheets("Set5").Visible = False
Sheets("Set61").Visible = True
Sheets("Set63").Visible = True
Sheets("Set64").Visible = True
Sheets("Set7").Visible = False
Sheets("File").Visible = False
Sheets("Fild").Visible = False
Sheets("Ts").Visible = True
Sheets("261d").Visible = True
Sheets("263d").Visible = True
End If
Case "R"
If strUserPassord = "O7" Then
ActiveWorkbook.Sheets("Main").Select
O.Enabled = False
GOODBYE.Enabled = True
S.Enabled = False
R.Enabled = True
A1.Enable = False
A3.Enabled = False
A4.Enabled = False
Sheets("Set4").Visible = False
Sheets("Set5").Visible = False
Sheets("Set61").Visible = False
Sheets("Set63").Visible = False
Sheets("Set64").Visible = False
Sheets("Set7").Visible = True
Sheets("File").Visible = False
Sheets("Fild").Visible = True
Sheets("Ts").Visible = True
Sheets("261d").Visible = False
Sheets("263d").Visible = False
End If
 
Case Else
MsgBox "Incorrect password or user name", vbCritical, Password
Application.Quit
End Select
End Sub
 
Last edited by a moderator:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Why are you checking the value of a non-existent variable strUserPassord?

Shouldn't you be checking strPassword?
 
Upvote 0
Eh, there is no code for hiding command buttons as far as I can see.:eek:

The only code i can see for hiding anything seems to be for worksheets.

Also what exactly are O, GOODBYE, S, R etc?:)
 
Upvote 0
They are command buttons and I want to either hide them or disable them based upon the User name & Password.
 
Upvote 0
How did you create these command buttons?

I'm pretty sure you can't refer to them in the way you are trying, however you created them.

Could be wrong about that mind you.:)

Does the code work at all?

ie does it do some things but not exactly what you want?

If that's the case I would suggest you set up a breakpoint (F9) or two and then step through the code (F8) and see what's happening.:)
 
Upvote 0
I created the command buttons using the toolbar and then assigned code to them to open certain spreadsheets. When you open the workbbok, it prompts you to enter your user name and then once you enter the correct one nothing happens. When I step into the code I recieve the run-timm error 424 Object required so it fails once it goes to the command button enable.
 
Upvote 0
Which toolbar did you use to create the command buttons?

If you are talking about command buttons on a worksheet then you could have created them with the Forms toolbar or the Control Toolbox toolbar.

Which one you used might have a bearing on what you are trying to do and how you refer to them.

I've got a feeling that whatever one you used you can't just refer to them by name.:)
 
Upvote 0
Eh, there is no code for hiding command buttons as far as I can see.:eek:

The only code i can see for hiding anything seems to be for worksheets.

Also what exactly are O, GOODBYE, S, R etc?:)


If the buttons are form buttons, I think the only way to hide them is to format them to move and size with cells and hide the row/col the button is in.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

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