Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 3 of 3

Thread: returning the computer name and user name

  1. #1
    Join Date
    7th May 2004
    Location
    Libya
    Posts
    619

    returning the computer name and user name

    Hi there
    could u pls reemind me of what is this?
    Application.CommandBars("ply").Enabled = False

    --------------------------------------------------------
    Could u pls tell me how to use this code ?
    i tried them, but............

    Function for returning the computer name

    'The function below will return the computer name for the
    ' machine running the code, works in both Windows NT and Windows95/98.

    VB:
    Private Declare Function GetComputerName Lib "kernel32" _ 
    Alias "GetComputerNameA" _ 
    (ByVal lpBuffer As String, nSize As Long) As Long 
     
     
    Function ReturnComputerName() As String 
        Dim rString As String * 255, sLen As Long, tString As String 
        tString = "" 
        On Error Resume Next 
        sLen = GetComputerName(rString, 255) 
        sLen = InStr(1, rString, Chr(0)) 
        If sLen > 0 Then 
            tString = Left(rString, sLen - 1) 
        Else 
            tString = rString 
        End If 
        On Error Goto 0 
        ReturnComputerName = UCase(Trim(tString)) 
    End Function 
    
    

    and this code as well:

    Function for returning the user name

    'The function below will return the user name for the logged on user,
    'works in both Windows NT and Windows95/98.

    VB:
    Public Declare Function GetUserName Lib "advapi32.dll" _ 
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 
     
    Function ReturnUserName() As String 
         ' returns the NT Domain User Name
        Dim rString As String * 255, sLen As Long, tString As String 
        tString = "" 
        On Error Resume Next 
        sLen = GetUserName(rString, 255) 
        sLen = InStr(1, rString, Chr(0)) 
        If sLen > 0 Then 
            tString = Left(rString, sLen - 1) 
        Else 
            tString = rString 
        End If 
        On Error Goto 0 
        ReturnUserName = UCase(Trim(tString)) 
    End Function 
     
     'If you don't want to return the network user name, but want to return the
     'user name that the user has registered with the application you can do this:
     
    ActiveUserName = Application.UserName 
    
    
    ******************
    Yours
    h

    Your Help Is Highly Appreciated

  2. #2
    Join Date
    6th September 2004
    Posts
    438

    Re: returning the computer name and user name

    A) This will disable a CommandBar called "ply"

    B) See code:

    VB:
    Sub doit() 
         
        MsgBox ReturnComputerName() 
         
    End Sub 
    
    
    Not really sure what your questions are!

    TJ
    Oh dear I need a beer
    Online Motorsport Game

  3. #3
    Join Date
    25th January 2003
    Location
    UK
    Posts
    2,745

    Re: returning the computer name and user name

    Hi h,

    The Ply commandbar is one of the right-click menubars (the sheet tab one). That line is disabling it - give it a try!

    The functions just return string values for your use:
    VB:
    Private Declare Function GetComputerName Lib "kernel32" _ 
    Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long 
     
    Public Declare Function GetUserName Lib "advapi32.dll" _ 
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 
     
    Function ReturnComputerName() As String 
        Dim rString As String * 255, sLen As Long, tString As String 
        tString = "" 
        On Error Resume Next 
        sLen = GetComputerName(rString, 255) 
        sLen = InStr(1, rString, Chr(0)) 
        If sLen > 0 Then 
            tString = Left(rString, sLen - 1) 
        Else 
            tString = rString 
        End If 
        On Error Goto 0 
        ReturnComputerName = UCase(Trim(tString)) 
    End Function 
     
    Function ReturnUserName() As String 
         ' returns the NT Domain User Name
        Dim rString As String * 255, sLen As Long, tString As String 
        tString = "" 
        On Error Resume Next 
        sLen = GetUserName(rString, 255) 
        sLen = InStr(1, rString, Chr(0)) 
        If sLen > 0 Then 
            tString = Left(rString, sLen - 1) 
        Else 
            tString = rString 
        End If 
        On Error Goto 0 
        ReturnUserName = UCase(Trim(tString)) 
    End Function 
     
    Sub Testem() 
        MsgBox "Computername : " & ReturnComputerName & vbNewLine & _ 
        "Username : " & ReturnUserName 
    End Sub 
    
    
    HTH
    Cross-poster? Read this: Cross-posters
    Struggling to use tags (including Code tags)? : Forum tags

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Replies: 3
    Last Post: June 17th, 2006, 03:38
  2. Instr returning "0" vs Find() returning result
    By niels in forum EXCEL HELP
    Replies: 1
    Last Post: March 23rd, 2006, 17:27
  3. Computer Name, ID
    By GrahamB in forum EXCEL HELP
    Replies: 1
    Last Post: March 18th, 2005, 17:00
  4. Replies: 18
    Last Post: October 20th, 2003, 10:07
  5. Replies: 3
    Last Post: September 11th, 2003, 00:47

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
  •  
porno