Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA - User name in group

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
519
US
I have a project were a user needs to enter an Excel "temporary" view when they open an excel document. My code works for the individual user, but I wanted to know if there was a way to determine if the user was part of a permissions group.

The goal is that if the person is not in the group, they go to the default layout. If they are in the permissions group, they get sent to a specific view.

This test code is working with regards to setting up and activating the temp view. I just want to see if I can add this one feature.


Example:

Group 1 (sent to temp view)
- Bob
- Fred
- Sam P.

Not in Group (not sent to temp view, but user view created)
- Mike
- Andy
- Sam Y.


Code Steps:

1) Check to see if user is in Permissions Group 1
IF Yes: Check if user has a temp view created​
If YES: Go to temp view​
If NO: Create temp view and activate it​

2) If user not in Permissions Group 1
IF Yes: Go to default view and check to see if user has temp view​
IF NO: create temp view, but stay in default view​

Code:
Sub test()

On Error GoTo create_view

user_name = VBA.Interaction.Environ$("UserName")
ActiveSheet.NamedSheetViews.GetItem(user_name).Activate

GoTo end_view


create_view:
ActiveSheet.NamedSheetViews.EnterTemporary
ActiveSheet.NamedSheetViews.GetItem("").Name = user_name
ActiveSheet.NamedSheetViews.GetItem(user_name).Activate

end_view:

End Sub

Thanks,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top