Solved

PC Name fro Excel VBA

Posted on 2011-09-21
4
233 Views
Last Modified: 2012-05-12
Please is it possible to return a computer name from Excel VBA? If so how?

In advance , many thanks

Norman Mitchell
0
Comment
Question by:NormanMitchell
  • 2
4 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 36572879
This might work, it does for me at least:
MsgBox Environ$("computername")

Open in new window

0
 
LVL 10

Expert Comment

by:ukerandi
ID: 36573180
MsgBox Environ("computername")
0
 
LVL 10

Accepted Solution

by:
ukerandi earned 500 total points
ID: 36573198
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
 

Author Closing Comment

by:NormanMitchell
ID: 36593415
Once again many thanks - you guys always come up trumps
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all theā€¦
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question