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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
Why are you checking the value of a non-existent variable strUserPassord?

Shouldn't you be checking strPassword?
 

iecalpoly

New Member
Joined
Nov 5, 2009
Messages
5
I have corrected that but still does not matter. Thank you for catching that.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
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?:)
 

iecalpoly

New Member
Joined
Nov 5, 2009
Messages
5

ADVERTISEMENT

They are command buttons and I want to either hide them or disable them based upon the User name & Password.
 

iecalpoly

New Member
Joined
Nov 5, 2009
Messages
5
I have reduced it to just look for the strUser but now I get run-time error 424 Object Required.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.:)
 

iecalpoly

New Member
Joined
Nov 5, 2009
Messages
5
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
Office Version
  1. 365
Platform
  1. Windows
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.:)
 

BC...

Board Regular
Joined
Sep 29, 2005
Messages
135
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.
 

Forum statistics

Threads
1,141,062
Messages
5,704,062
Members
421,326
Latest member
pfaustino

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
Top