Dmitriy Kravchuk
Dmitriy Kravchuk

Reputation: 85

Run vba module with specify of username

is it possible to run excel module when workbook opened by certain user? The idea is very simple - refreshing all data source when excel workbook opened by certain user, save and close. Another way it just opens.

Upvotes: 0

Views: 59

Answers (2)

Sergius
Sergius

Reputation: 1

Also it is possible to check Excel user's name by using

If Application.UserName = “bWayne” Then
…
End If

in Workbook_Open() procedure.

Upvotes: 0

BruceWayne
BruceWayne

Reputation: 23283

I'm not sure how "secure" this is, but it worked for me. Note that you need to put this in the "ThisWorkbook" Object (not a Module):

Private Sub Workbook_Open()
If Environ$("Username") = "bWayne" Then
    MsgBox ("Hi Bruce")
   ' Do whatever
End If
End Sub

Save as .xlsm and when you open it, if the username is bWayne, the message box will show...otherwise, nothing happens.

Upvotes: 1

Related Questions