Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

User Form VBA to Unhide worksheets

0

Hi everyone, I actually need help. I am doing a college work and I managed to do user form login and inserted a code on "this Workbook" to all the worksheets except the login worksheet and everything is working fine but I want to unhide the rest of the worksheet when I login.

Those are the codes I used, so please help me if you guys can

This one for the userform

Private Sub cmdcheck_Click()
Dim username, password As String
username = txtUser.Text
password = txtpass.Text
If txtUser.Value = "aj" And txtpass.Value = "45423240" Then
MsgBox "WELCOME TO MY ASSIGNMENT TASK 2:).To unhide the worksheet click ADMIN ICON", vbInformation
Unload Me 'unload this form
Else
MsgBox "You Entered the wrong information,Please enter lower case only.", vbCritical
End If
End Sub

This for the "THIS WORKBOOK"

Private Sub Workbook_Open()
 Dim ws As Worksheet
For Each ws In Worksheets
 If ws.Name <> "MAINLOGIN" Then
ws.Visible = xlSheetHidden
 End If
 Next ws
 PopUp.Show
 End Sub

I would really apricate if any one can share his thoughts

Post Edited
Title: Title was not descriptive.
CODE Tags: You must add [CODE][/CODE] tags around your code! (click the CODE button to do this when creating a post)
Tags: Tags were updated to reflect the topic of the question.
Answer
Discuss

Answers

0
Selected Answer

This line of code in your On_Open event procedure hides all the worksheets, "ws.Visible = xlSheetHidden". "ws.Visible = xlSheetVisible" would make them visible.

However, worksheets are visible by default. They can only be invisible if they were made so at some time before saving the workbook. Therefore, instead of making them visible upon opening the workbook consider controlling the process of making them invisible at the time of saving.

Since you are using VBA to hide the sheets, consider making them 'xlSheetVeryHidden'. Sheets with the attribute xlSheetHidden are listed as hidden. The user can unhide them from Format > Hide & Unhide > Unhide Sheet. Sheets with the attribute is xlSheetVeryHidden are not listed and can be made visible only by setting the 'Visible' property in the VB Editor's properties window or using VBA to do that.

BTW, "Dim username, password As String" is equivalent to "Dim username As Variant, password As String". What you probably intended should look like this:-

Dim username As String, password As String
Discuss

Discussion

Thank's a lot. it is very helpfull, and it works.  
wedivetro (rep: 2) Dec 4, '17 at 1:52 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login