Closed Thread
Results 1 to 2 of 2

Vba username code issue

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2014
    Location
    peterlee, england
    MS-Off Ver
    office pro plus 2013
    Posts
    5

    Vba username code issue

    Hi

    Ive got an issue with a get username function:

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias _
    "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, _
    lpnLength As Long) As Long
     
    Private Const NO_ERROR = 0
    Private Const ERROR_NOT_CONNECTED = 2250&
    Private Const ERROR_MORE_DATA = 234
    Private Const ERROR_NO_NETWORK = 1222&
    Private Const ERROR_EXTENDED_ERROR = 1208&
    Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
     
    Function WinUsername() As String
     
    Dim strBuf As String, lngUser As Long, strUn As String
    strBuf = Space$(255) '//Clear buffer
    lngUser = WNetGetUser("", strBuf, 255)
    If lngUser = NO_ERROR Then
    strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
    WinUsername = strUn
    Else
    WinUsername = "Error :" & lngUser
    End If
    End Function
    Now the above command will be used in a shared workbook and works for my user, but as soon as another user loads the workbook, the username stays the same and only works if the formula is deleted and re-typed.

    Is there a way around this as I need the process to be fully automated.

    Thanks in advance

    A very confused Adam J

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vba username code issue

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Username Code help - Slow processing speed
    By JBurton1986 in forum Excel General
    Replies: 6
    Last Post: 02-21-2014, 06:53 AM
  2. Username/Password Login userform code
    By Nitefox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2014, 02:43 PM
  3. [SOLVED] Environ Username issue
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2013, 11:55 AM
  4. [SOLVED] Username and Password Form - Show Username in Sheet
    By ryan180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 07:06 PM
  5. [SOLVED] UserName login code
    By Bruise in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2006, 12:10 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1