Computer "name"

  • Thread starter Thread starter D.S.
  • Start date Start date
D

D.S.

Can Excel be programmed to test for my computer's name?

I'd like to create an If/Then statement by looking at the computer name the
procedure is running on. User name won't work because it's the same user in
both cases, just running the procedure on different machines.

d.s.
 
Environ() function gives you lots of these. I think that environ(5) is
computer name.

Use different indexes and test the function

regards,

OssieMac
 
Thanks, looks like that's going to work, at least it's working with the
Excel 2003 I'm running on this machine. (that's a new one for me, never
noticed it before)

d.s.
 
It might be 5 on yours, but not on mine. Should always use the name not
index.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
The index number for the Environ function will vary from one machine to
another, depending on the operating system and other installed software.
You should never call Environ using an index number. Always use the name of
the variable. Moreover, I have on rare occassion found that
Environ("ComputerName") does not properly return the computer name.
Therefore, I always use an API call, part of my standard library.

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

Function ComputerName() As String
Dim S As String
Dim L As Long
L = 256
S = String$(L, 0)
GetComputerName S, L
ComputerName = Left(S, L)
End Function

Sub Test()
Dim CompName As String
CompName = ComputerName()
MsgBox "Computer Name: " & CompName
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top