ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get computer name (https://www.excelbanter.com/excel-programming/309488-get-computer-name.html)

Eric Marple

Get computer name
 
Is there a method to retreive the computer name?

Chip Pearson

Get computer name
 
Eric,

Try something like

Debug.Print Environ("Computername")



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Eric Marple" wrote in
message ...
Is there a method to retreive the computer name?




Kevin

Get computer name
 
I use this in VBA within Access. It should also work in
Excel because it is using the Windows API

Function GetComputerName() As String
Dim lngLen As Long, lngX As Long
Dim strName As String

lngLen = 32
strName = String$(lngLen, 0)
lngX = apiGetComputerName(strName, lngLen)
If lngX < 0 Then
GetComputerName = Left$(strName, lngLen)
Else
GetComputerName = ""
End If

End Function

You also need the following in the declarations for the
module where the function exists.

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

Hope that helps!

Kevin

-----Original Message-----
Is there a method to retreive the computer name?
.


Kevin

Get computer name
 
P.S. I have tested the code I just sent you in Excel and
it does work. I inserted the code into a Module for the
Workbook. I put the function header in the declarations. I
then called the function from a subroutine I run at
startup and inserted the value into a cell in my
spreadsheet and it works just fine.

Hope that helps!

Kevin
-----Original Message-----
Is there a method to retreive the computer name?
.



All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com