• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

PC Name fro Excel VBA

Please is it possible to return a computer name from Excel VBA? If so how?

In advance , many thanks

Norman Mitchell
0
NormanMitchell
Asked:
NormanMitchell
  • 2
1 Solution
 
StephenJRCommented:
This might work, it does for me at least:
MsgBox Environ$("computername")

Open in new window

0
 
ukerandiCommented:
MsgBox Environ("computername")
0
 
ukerandiCommented:
Private Declare Function GetComputerName Lib "kernel32" _
        Alias "GetComputerNameA" ( _
        ByVal lpBuffer As String, _
        ByRef nSize As Long) As Long


Private Sub CommandButton1_Click()

MsgBox CompName()
End Sub




Public Property Get ComputerName() As String

  Dim stBuff As String * 255, lAPIResult As Long
  Dim lBuffLen As Long
 
  lBuffLen = 255
 
  lAPIResult = GetComputerName(stBuff, lBuffLen)
 
  If lBuffLen > 0 Then ComputerName = Left(stBuff, lBuffLen)

End Property
Public Function CompName() As String
  CompName = ComputerName
End Function
0
 
NormanMitchellAuthor Commented:
Once again many thanks - you guys always come up trumps
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now