Excel VBA hide/unhide with Login Password on OneDrive Workbook

jaylauzon

New Member
Joined
Aug 25, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I'm trying to build a Excel workbook with login acces. Me and my team need to work on the same workbook at the same time on OneDrive Cloud. But I need to hide some worksheet when teamate 'X' open the workbook. When teamate 'Y' work at the same time I don't want to hide any worksheet. However, when teammate 'Y' open the workbook, he unhide all worksheet for everyone one, that's my problem. Could you look at my code and give me some tips!

Private Sub Label3_Click()
Dim WS As Worksheet

'//////////ADMIN USER/////////
If Me.TextBox1.Value = "AHP123" And Me.TextBox2.Value = "AHP123" Or _
Me.TextBox1.Value = "michelle.corneau" And Me.TextBox2.Value = "michelle.corneau" Or _
Me.TextBox1.Value = "linda.daoust" And Me.TextBox2.Value = "linda.daoust" _
Then

For Each WS In Worksheets
WS.Visible = True
Next

Application.Visible = True
Unload Me


'//////////SUPERVISOR USER/////////
ElseIf Me.TextBox1.Value = "lyne.henripin" And Me.TextBox2.Value = "lyne.henripin" Or _
Me.TextBox1.Value = "jf.provencher" And Me.TextBox2.Value = "jf.provencher" _
Then

Worksheets("Productivity Tracking").Visible = True
Worksheets("Grille Des Aquis").Visible = True
Worksheets("Daily Stats").Visible = True
Worksheets("Weekly Stats").Visible = True
Worksheets("MAHP Highlights").Visible = True
Worksheets("Claims").Visible = True
Worksheets("Weekly Performance").Visible = True
Worksheets("Daily Performance").Visible = True
Worksheets("Weekly Forecast").Visible = True
Worksheets("CSO Tire").Visible = True
Worksheets("Deal").Visible = False
Worksheets("APS").Visible = True
Worksheets("Email-Fin de quart").Visible = True
Worksheets("Vacance (Jour)").Visible = True
Worksheets("Vacance (A)").Visible = True
Worksheets("Vacance (B)").Visible = True
Worksheets("Slotting Capacity").Visible = True
Worksheets("Slotting Performance").Visible = True
Worksheets("Rapport OPS").Visible = True
Worksheets("Reception Summary").Visible = True
Worksheets("DWO-New SKU").Visible = False

Application.Visible = True
Unload Me

End If

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi there. Is there anything in your code that's not working? It's a bit hard to tell without seeing your userform, but one thing that comes to mind is using the Environ("username") function to pull the Windows user name, assuming each user is logging into their own window's profiles.

VBA Code:
Private Sub Label3_Click()
Dim WS As Worksheet

Dim user As String: user = Environ("username")

If user = "AHP123" Or user = "michelle.corneau" Or user = "linda.daoust" Then

'//////////ADMIN USER/////////
    For Each WS In Worksheets
        WS.Visible = True
    Next

    Application.Visible = True
    Unload Me

'//////////SUPERVISOR USER/////////
Else
    Worksheets("Productivity Tracking").Visible = True
    Worksheets("Grille Des Aquis").Visible = True
    Worksheets("Daily Stats").Visible = True
    Worksheets("Weekly Stats").Visible = True
    Worksheets("MAHP Highlights").Visible = True
    Worksheets("Claims").Visible = True
    Worksheets("Weekly Performance").Visible = True
    Worksheets("Daily Performance").Visible = True
    Worksheets("Weekly Forecast").Visible = True
    Worksheets("CSO Tire").Visible = True
    Worksheets("Deal").Visible = xlVeryHidden
    Worksheets("APS").Visible = True
    Worksheets("Email-Fin de quart").Visible = True
    Worksheets("Vacance (Jour)").Visible = True
    Worksheets("Vacance (A)").Visible = True
    Worksheets("Vacance (B)").Visible = True
    Worksheets("Slotting Capacity").Visible = True
    Worksheets("Slotting Performance").Visible = True
    Worksheets("Rapport OPS").Visible = True
    Worksheets("Reception Summary").Visible = True
    Worksheets("DWO-New SKU").Visible = xlVeryHidden

    Application.Visible = True
    Unload Me

End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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