Machine name

  • Thread starter Thread starter Avner
  • Start date Start date
A

Avner

Hi
You can get all sort of information in INFO function.
But,
How can i get the local machine name ?
avner
:(
 
|| Hi
|| You can get all sort of information in INFO function.
|| But,
|| How can i get the local machine name ?
|| avner
|| :(
||
||
|| ---
|| Message posted

Start-settings-control panel-network-identification
 
Avner,

You need to use the GetComputerName API call in a VBA function.
For example,

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

Function ComputerName() As String
Dim L As Long
Dim R As Long
Dim S As String
S = String$(255, " ")
L = Len(S)
R = GetComputerName(S, L)
ComputerName = Left(S, L)
End Function

You can then call this from a worksheet cell with =COMPUTERNAME()


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Dim S As String
S = String$(255, " ")
L = Len(S)

Couldn't you instead do
dim S as string * 255
L = 255
and skip having to fill up the string with characters?
 
Yes, that will work.


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

Jonathan Rynd said:
Couldn't you instead do
dim S as string * 255
L = 255
and skip having to fill up the string with characters?
reply.
 
Back
Top