Opening an Excel file based on the user

Solved
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.

6 answers

  1. Boisgontierjacques Posted messages 177 Status Member 64
     
    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
    2
  2. Boisgontierjacques Posted messages 177 Status Member 64
     
    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
    1
  3. Boisgontierjacques Posted messages 177 Status Member 64
     
    Hello,

    Put the correspondence table on another sheet and name this table users.

    Jacques Boisgontier
    1
  4. Fethi51 Posted messages 4 Status Member
     
    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
    0
  5. Fethi51 Posted messages 4 Status Member
     
    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
    0
  6. Fethi51 Posted messages 4 Status Member
     
    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.
    0