VBA to hide worksheets based on windows user names..

MarkRush

New Member
Joined
Mar 6, 2018
Messages
28
I have been working on a new quoting tool for my organization and I guess I did such a great job( in large part to this forum! Thank you to everyone!:):):):)) that the Engineers are worried that the sales people will create quotes without engineering overview and create some serious issues..

I have been tasked to lock portions of the quote tool based on if a Sales Engineer or other person opens the workbook. I can do this easily with a password prompt but passwords are prone to leaks, forgetting, etc etc..

I would really like to do this by using the Environ statement I found the following that looks like it will work, but would require me to duplciate the macro based on every username allowed to have full access.

Code:
WinUser = Environ("USERNAME") ' Windows username

Private Sub Auto_Open()
' This macro unhides sheets when the user set below opens the workbook
' It is a Private Sub to prevent it being listed with other macros

On Error Resume Next

If Application.UserName = "[I]Enter Username Here[/I]" Then
     Worksheets("Sheet2").Visible = True ' First sheet to be made visible
     Worksheets("Sheet3").Visible = True ' More can be listed here
End If

End Sub

Private Sub Auto_Close()
' This macro ensures the sheets are hidden when any user closes the workbook

On Error Resume Next

Worksheets("Sheet2").Visible = xlSheetVeryHidden ' Hide worksheets
Worksheets("Sheet3").Visible = xlSheetVeryHidden ' Other sheets to be hidden

End Sub

What I would like to do is have a worksheet with a list of all Engineer usernames and search that list to see who gets unfettered access. And then once the workbook is complete , Set a flag that changes what Sales people can see.

As an example. Sales opens workbook their username isn't defined and they can only see sheets 1-5, Engineer opens workbook, Their username is defined and they can see sheets 1-10. Engineer processes all the forms, Completes quote then presses a macro button called return to sales .. Sales opens completed workbook and can now see sheets 1-5, 9 and 10.. Sheets 7,8 and 9 are VeryHidden.

Any help would be much appreciated..
 
Hi,
sorry to say no idea what you have going on in your project - my code should only create sheet User List once.
Suggest step through your code to see where this happens to figure out why it is doing it.

Dave
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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