+ Reply to Thread
Results 1 to 3 of 3

computer_name

Hybrid View

  1. #1
    Simplefi
    Guest

    computer_name

    Is there a simple "formula" for adding the computername to a cell without
    resorting to a VBA macro.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Simplefi,

    Not that I am aware of. The only method I have seen and used is a user defined function that calls the Windows API. It is quite easy to install and use. Here are the code and the directions to install the API call and user defined function.

    Installation Directions...
    1) Copy the code in this post using CTRL+C
    2) Open the Workbook the macro will be installed in.
    3) Press ALT+F11 to launch the VBA Editor.
    4) Press ALT+I to activate the Insert Menu
    5) Press M to insert a new VBA module into the Workbook.
    6) Press CTRL+V to paste the macro code into the module.
    7) Press CTRL+S to save the Workbook changes

    Using the Macro...
    Simply use the Formula below in a cell to return the computr's name.

    =ComputerName()

    Declare Function GetComputerName _
      Lib "kernel32" _
        Alias "GetComputerNameA" _
          (ByVal lpBuffer As String, _
           nSize As Long) As Long
    
    Function ComputerName() As String
    
       Dim CompName As String * 256
       Dim RetVal
    
         CompName = String(0, 256)
         RetVal = GetComputerName(CompName, 256)
         Chars = InStr(1, CompName, Chr$(0)) - 1
         
         If Chars > 0 Then
            ComputerName = Left(CompName, Chars)
         Else
            ComputerName = ""
         End If
       
    End Function
    Sincerely,
    Leith Ross

  3. #3
    Simplefi
    Guest

    Re: computer_name

    Leith,
    thanks for reply. I'm going to have a play with your suggestion.
    Below is code I put together last night - it does what I need.
    The important bits being
    ..cells(Row...................
    and
    the system var Environ(..........

    Best Regards
    Simplefi

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    With Sheets("Sheet3")
    .Select
    .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Select
    End With



    Selection.Value = "Saved by " & Environ("UserName") & Date
    Sheets("sheet1").Select


    End Sub

    "Leith Ross" wrote:

    >
    > Hello Simplefi,
    >
    > Not that I am aware of. The only method I have seen and used is a user
    > defined function that calls the Windows API. It is quite easy to
    > install and use. Here are the code and the directions to install the
    > API call and user defined function.
    >
    > Installation Directions...
    > 1) Copy the code in this post using CTRL+C
    > 2) Open the Workbook the macro will be installed in.
    > 3) Press ALT+F11 to launch the VBA Editor.
    > 4) Press ALT+I to activate the Insert Menu
    > 5) Press M to insert a new VBA module into the Workbook.
    > 6) Press CTRL+V to paste the macro code into the module.
    > 7) Press CTRL+S to save the Workbook changes
    >
    > Using the Macro...
    > Simply use the Formula below in a cell to return the computr's name.
    >
    > =ComputerName()
    >
    >
    > Code:
    > --------------------
    >
    > Declare Function GetComputerName _
    > Lib "kernel32" _
    > Alias "GetComputerNameA" _
    > (ByVal lpBuffer As String, _
    > nSize As Long) As Long
    >
    > Function ComputerName() As String
    >
    > Dim CompName As String * 256
    > Dim RetVal
    >
    > CompName = String(0, 256)
    > RetVal = GetComputerName(CompName, 256)
    > Chars = InStr(1, CompName, Chr$(0)) - 1
    >
    > If Chars > 0 Then
    > ComputerName = Left(CompName, Chars)
    > Else
    > ComputerName = ""
    > End If
    >
    > End Function
    >
    > --------------------
    >
    >
    > Sincerely,
    > Leith Ross
    >
    >
    > --
    > Leith Ross
    > ------------------------------------------------------------------------
    > Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
    > View this thread: http://www.excelforum.com/showthread...hreadid=553447
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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