Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney, New South Wales, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identify who runs a macro (Excel97)

    Within a macro in a shared excel file, is there a way of determining who is running that macro? (username or IP address)

    Dim strUser as String
    strUser = (the thing I'm looking for that tells me the users name)
    msgbox "Hello" & strUser

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify who runs a macro (Excel97)

    See if one of the answers in <!post=This Thread,293049>This Thread<!/post> will give you what you want.
    Legare Coleman

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney, New South Wales, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify who runs a macro (Excel97)

    Thank you very much
    exactly what I wanted
    <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Identify who runs a macro (Excel97)

    See <post#=404436>post 404436</post#> in the Access forum for code to retrieve the computer name and network user name (the latter is only useful in a network environment, of course).

  5. #5
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney, New South Wales, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify who runs a macro (Excel97)

    It works well on all the windows2000+ machines but was returning a blank on the two machines we have with windows 98.
    Was it called something different previously.
    I also tried Environ("computername") and got a blank on the Win98 but a result on Win2000

  6. #6
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney, New South Wales, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify who runs a macro (Excel97)

    Thank you Hans
    Lots to try to work out in that solution, so a bit of a delay in getting back to you

    <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29> Unfortunately I was unable to get the code that retrieves the computer name to work
    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> But I did get the code to retrieve the network user name to work


    <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> With the network user name I am able to do what I wanted and it works on all the different versions of windows too.

    Does anyone know how to retrieve the user name that is entered in Tools>Options>General>User Name
    This is the name that appears when you try to open a file that someone else has open
    File.xls is being modified by
    User Name


    Regards Paul

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Identify who runs a macro (Excel97)

    That name is Application.Username.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Identify who runs a macro (Excel97)

    If you copy the following code into a new module:

    Private Declare Function GetComputerNameA Lib "kernel32" _
    (ByVal lpBuffer As String, nSize As Long) As Long

    Public Function GetComputerName() As String
    Dim dwLen As Long
    Dim strString As String
    'Create a buffer
    dwLen = 32
    strString = String(dwLen, "X")
    'Get the computer name
    GetComputerNameA strString, dwLen
    'Get only the actual data
    strString = Left(strString, dwLen)
    'Return the computer name
    GetComputerName = strString
    End Function

    Then activate the Immediate window (Ctrl+G), type

    ? GetComputerName

    and press Enter, do you get an error message?

  9. #9
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney, New South Wales, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify who runs a macro (Excel97)

    Thank you Hans

    I've got all three working now (& on each of the different Operating Systems)
    application.username
    net user name
    computer name

    Thank you very much for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •