-2

I have three worksheets in a workbook. I want to show a specific user form when the user selects one of the worksheets. How can I achieve this in VBA?

1
  • I have looked at your recent posts. You make no effort whatsoever to explain your problem in any detail and show us no evidence that you have tried anything yourself. Please stop posting duplicates and vague questions. We are willing to help you if you show us what you've got so far and add some detail.
    – CallumDA
    May 6, 2016 at 8:42

1 Answer 1

1

There are several ways to retrieve the current user name. If you want to retrieve the OS user then this is the best solution:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, lpnSize As Long) As Long

Public Function GetOSUser() As String
    Dim lpBuffer As String * 25

    GetUserName lpBuffer, 25
    GetOSUser = Left(lpBuffer, InStr(lpBuffer, vbNullChar) - 1)
End Function

Based on the return value of GetOSUser() you can then select the user form to display to the user.

1
  • I get the impression its a different userform based on the selected sheet, rather than the user - It's extremely ambiguous but this is almost a duplicate of a previous question : superuser.com/questions/1073210/…
    – CallumDA
    May 6, 2016 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .