Opening an Excel file based on the user
Solved
Fethi51
Posted messages
4
Status
Member
-
Fethi51 Posted messages 4 Status Member -
Fethi51 Posted messages 4 Status Member -
Hello,
I would like to create a macro in a file so that each time it is opened, and depending on the user (Author's name in Excel), the file opens with a filter for that person.
Thank you in advance for your help.
I would like to create a macro in a file so that each time it is opened, and depending on the user (Author's name in Excel), the file opens with a filter for that person.
Thank you in advance for your help.
6 answers
-
Good evening,
Private Sub Workbook_Open()
name = Environ("username")
Sheets(1).Cells.AutoFilter Field:=1, Criteria1:=name
End Sub
https://www.cjoint.com/c/CLpvfEfhcEO
Jacques Boisgontier -
Private Sub Workbook_Open()
name = Environ("username") ' network name
Sheets(1).Cells.AutoFilter Field:=1, Criteria1:=name
End Sub
or
Private Sub Workbook_Open()
name = Application.UserName ' office user
Sheets(1).Cells.AutoFilter Field:=1, Criteria1:=name
End Sub
or
Private Sub Workbook_Open()
name = Application.UserName
initials = Application.VLookup(name, [users], 2, False) ' correspondence table
If Not IsError(initials) Then
Sheets(1).Cells.AutoFilter Field:=1, Criteria1:=initials
End If
End Sub
https://www.cjoint.com/c/CLpxft99txX
Jacques Boisgontier -
Hello,
Put the correspondence table on another sheet and name this table users.
Jacques Boisgontier -
Thank you for your reply
but the "name" refers to the session name or others, how to deal with the name in Office instead?
https://www.cjoint.com/c/CLpwaWFjcFB
if possible with initials based on the names -
Hello,
Thank you very much
I just can't create a correspondence table, and to avoid using it since there will be insertions of rows and columns that might cause misalignment, is it possible to put the correspondences between first name/last name and initials directly into the macro?
Private Sub Workbook_Open()
name = Application.UserName
initials = Application.VLookup(name, [users], 2, False) ' correspondence table
If Not IsError(initials) Then
Sheets(1).Cells.AutoFilter Field:=1, Criteria1:=initials
End If
End Sub -
I couldn't figure out how to identify a correspondence table, so I managed like this:
name = Application.UserName
initials = Application.VLookup(name, Range("CO3:CP8"), 2, False) 'correspondence table
If Not IsError(initiales) Then
Sheets(1).Cells.AutoFilter Field:=13, Criteria1:=initiales
End If
Overall, a huge THANK YOU, it works very well...
See you soon.