Solved

PC Name fro Excel VBA

Posted on 2011-09-21
4
218 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now